From 6bc098e57b6ecd4751728c68fc37077606d611e7 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 9 Oct 2025 23:49:22 +0200 Subject: [PATCH] HTML artifacts call window.complete() when page loads - Inject before - HTML artifacts are long-running and don't time out - Console logs are sent immediately, completion signals when page is ready - Removes need for artificial timeout in HTML artifacts --- .../web-ui/src/tools/artifacts/HtmlArtifact.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 {