diff --git a/packages/runtime-playground/src/browser-actions-runner.ts b/packages/runtime-playground/src/browser-actions-runner.ts index 6536688b..a3dd144c 100644 --- a/packages/runtime-playground/src/browser-actions-runner.ts +++ b/packages/runtime-playground/src/browser-actions-runner.ts @@ -474,16 +474,16 @@ export async function runBrowserActionsCommand({ try { const screenshotCaptureBudgetMs = adaptiveCaptureNavigationUnsettled ? Math.min(adaptiveCaptureBudgetMs, livenessRemainingWallTimeMs(startedAtMs, totalTimeoutMs)) : 0 if (adaptiveCaptureNavigationUnsettled && screenshotCaptureBudgetMs <= 0) throw new Error("Adaptive screenshot capture budget was exhausted before capture started.") - const screenshotCapture = artifactSession.writeGenerated("screenshot", "screenshot.png", (path) => page.screenshot({ path, fullPage: true }).then(() => undefined)) if (adaptiveCaptureNavigationUnsettled) { - await withBrowserCommandLiveness({ + const screenshot = await withBrowserCommandLiveness({ command: "wordpress.browser-actions", phase: "adaptive partial screenshot capture", - operation: screenshotCapture, + operation: page.screenshot({ fullPage: true }), policy: { wallTimeoutMs: screenshotCaptureBudgetMs, idleTimeoutMs: 0 }, }) + await artifactSession.writeBuffer("screenshot", "screenshot.png", screenshot) } else { - await screenshotCapture + await artifactSession.writeGenerated("screenshot", "screenshot.png", (path) => page.screenshot({ path, fullPage: true }).then(() => undefined)) } screenshotSha256 = await fileSha256(screenshotPath) if (capture.has("dom-snapshot")) { diff --git a/tests/browser-actions-navigation-capture.browser.test.ts b/tests/browser-actions-navigation-capture.browser.test.ts index 54e44fe4..b69355c5 100644 --- a/tests/browser-actions-navigation-capture.browser.test.ts +++ b/tests/browser-actions-navigation-capture.browser.test.ts @@ -133,7 +133,15 @@ test("adaptive capture classifies unresolved navigation and retains partial evid assert(Date.now() - startedAt < 1_500, "capture settlement must remain inside the command budget") await access(join(artifactRoot, "files/browser/steps.jsonl")) await access(join(artifactRoot, "files/browser/network.jsonl")) - await access(join(artifactRoot, "files/browser/screenshot.png")) + const screenshotPath = join(artifactRoot, "files/browser/screenshot.png") + const screenshotUnavailable = adaptive.result.diagnostics.some(({ code }: { code: string }) => code === "browser_adaptive_capture_screenshot_unavailable") + if (result.artifact.summary.screenshot) { + assert.equal(screenshotUnavailable, false) + await access(screenshotPath) + } else { + assert.equal(screenshotUnavailable, true) + await assert.rejects(access(screenshotPath)) + } await assert.rejects(access(join(artifactRoot, "files/browser/snapshot.html"))) } finally { await context.close()