diff --git a/packages/web-ui/src/tools/artifacts/HtmlArtifact.ts b/packages/web-ui/src/tools/artifacts/HtmlArtifact.ts index 21703b69..3022bac3 100644 --- a/packages/web-ui/src/tools/artifacts/HtmlArtifact.ts +++ b/packages/web-ui/src/tools/artifacts/HtmlArtifact.ts @@ -101,8 +101,21 @@ export class HtmlArtifact extends ArtifactElement { }, }; + // Inject window.complete() call at the end of the HTML to signal when page is loaded + // HTML artifacts don't time out - they call complete() when ready + let modifiedHtml = html; + if (modifiedHtml.includes("")) { + modifiedHtml = modifiedHtml.replace( + "", + "", + ); + } else { + // If no closing tag, append the script + modifiedHtml += ""; + } + // Load content - this handles sandbox registration, consumer registration, and iframe creation - sandbox.loadContent(sandboxId, html, this.runtimeProviders, [consumer]); + sandbox.loadContent(sandboxId, modifiedHtml, this.runtimeProviders, [consumer]); } override get content(): string {