feat(browser): expose writeArtifact under a public name and document it - #345
Merged
ankitranjan7 merged 1 commit intoAug 18, 2026
Merged
Conversation
__webcmdWriteArtifact was the only write path out of the QuickJS sandbox and its dunder prefix reads as private, so programs would not call it. Expose the same function as globalThis.writeArtifact, keep the dunder as an alias, and return the receipt instead of swallowing it. Also accept a null contentType, which is what JSON.stringify produces for the two-argument call, and document artifacts in the browser-run reference including the download path and how a receipt is redeemed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
🟢 No documentation gap found — medium confidenceThe automated review found no documentation gap in the supplied changes. This review is advisory and does not block merging. |
ankitranjan7
added a commit
that referenced
this pull request
Aug 18, 2026
#344) * fix(browser): add btoa/atob/TextEncoder/TextDecoder to the run sandbox The QuickJS sandbox for `browser run` exposed working base64 and UTF-8 codecs only under private-looking `__webcmd*` names, so programs reaching for the standard globals hit `'TextEncoder' is not defined`. Alias them to the platform names in the existing platform shim. btoa/atob are implemented as latin1 binary-string codecs rather than composed with the UTF-8 helpers, which would corrupt binary input. Buffer stays absent — it is Node-only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * feat(browser): expose writeArtifact under a public name and document it (#345) __webcmdWriteArtifact was the only write path out of the QuickJS sandbox and its dunder prefix reads as private, so programs would not call it. Expose the same function as globalThis.writeArtifact, keep the dunder as an alias, and return the receipt instead of swallowing it. Also accept a null contentType, which is what JSON.stringify produces for the two-argument call, and document artifacts in the browser-run reference including the download path and how a receipt is redeemed. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> * Feat/evals (#349) * benchmakrs added * fix: removed missing refs from readme * feat(benchmarks): support OpenAI as judge provider * fix: screenshot upload * feat: added cost support * docs: design benchmark-specific judge prompts * feat(benchmarks): split general and stealth judge prompts * Delete docs/superpowers/specs directory * chore: bump version metadata for 0.7.0 release * Revert "chore: bump version metadata for 0.7.0 release" This reverts commit c69011f. * feat(benchmarks): expose full Webcmd skill pack to Codex evals * feat(benchmarks): clarify stealth captcha handling * fix: added support for webcmd browser skills only * feat(benchmarks): run eval attempts in parallel * fix(benchmarks): isolate parallel webcmd sessions * test(benchmarks): cover parallel webcmd sessions * pi support (#313) * chore(benchmarks): pin webcmd 0.7.1 * refactor: disable concurrency in benchmark evaluation and remove integration tests * feat(benchmarks): support Codex subscription evals * docs(skills): improve browser diff and form guidance * docs(skills): sync browser skill sources --------- Co-authored-by: beubax <tejasr@bu.edu> Co-authored-by: Tejas <48682479+beubax@users.noreply.github.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Rishabh <33702025+rishabhraj36@users.noreply.github.com> Co-authored-by: beubax <tejasr@bu.edu> Co-authored-by: Tejas <48682479+beubax@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #339.
What
__webcmdWriteArtifactwas the only way to get bytes out of the QuickJS sandbox, and its dunder prefix reads as "private implementation detail" to anything that finds it. An internal agent-behaviour eval showed an agent capture a download correctly, fail to find any way to persist it, then fall back to scraping the on-page preview and hand-writing a mismatched file.globalThis.writeArtifact(filename, bytes, contentType?)is now the public name. Bare global, matching the flatpage/context/browserprecedent — awebcmd.*namespace would be a second discovery hop for one function, and the sandbox has no other namespaced surface to hang it off.__webcmdWriteArtifactstays as a direct alias to the same function, so in-flight programs and the internalpage.screenshot({ path })wrapper are unaffected.await __webcmdHostCall(...)with noreturn, so the receipt the host already produced was discarded. browser run: __webcmdWriteArtifact is the only way out of the sandbox and is documented nowhere #339's check requires the receipt back, and the screenshot wrapper never needed it, which is why nothing caught this.Uint8Arrayor anythingnew Uint8Array(...)accepts.Bug found while testing the two-argument call
Calling
writeArtifact(name, bytes)without acontentTypefailed withBROWSER_RUN_INVALID_INPUT.JSON.stringify([f, b, undefined])yields[f, b, null], and the host guard testedargs[2] !== undefined && typeof args[2] !== 'string', sonullfell through to the rejection. Loosened toargs[2] != null; the downstream default was alreadyargs[2] ?? artifactContentType(...), which handlesnullcorrectly. Only the screenshot wrapper called this before, and it always passes a content type, so the two-argument path had never run.Docs
skills/webcmd-browser/references/browser-run-playwright.mdgains an "Artifacts: getting bytes out of the sandbox" section covering the signature, the download path, and receipt redemption.That file is being rewritten in #342. This PR branches off
main's version rather than #342's, so it does not carry that rewrite — but the section is written in #342's structure and tone (short prose, fenced examples, worked cases) so it slots straight into its "Files and binary data" area on merge.Two things I verified in the sandbox before writing the example, rather than assuming:
download.createReadStream()throwsReadable streams are not available in the QuickJS sandbox. This is the obvious thing to reach for after catching a download event, and it is a dead end.download.saveAs('relative/name.csv')already works and routes through the artifact sink, producing a receipt inoutput.artifactswith nowriteArtifactcall at all. That is the correct answer for the download case and was documented nowhere. The docs now lead with it.src/skills.test.tsasserted the old/artifact paths/iheading; retargeted to/artifacts/iplus a literalwriteArtifact(check, which is a stronger assertion than the heading text.Tests
returns a redeemable receipt from %s, parameterized overwriteArtifactand__webcmdWriteArtifact, insrc/browser/run/runner.test.ts. Each writes through aLocalBrowserRunArtifactSinkpointed at a temp dir, asserts the returned receipt's shape, asserts it equals the entry inoutput.artifacts, and reads the bytes back off disk at<baseDir>/<artifactId>/<filename>afterrunreturns. Uses a nested logical path and a multi-byte character so the byte count is a real check.Counts
npm run buildclean.npx vitest run --project unit:main, no Chromium installed (stated baseline)main, Chromium installedrunner.test.tsis gated on a local Chromium binary, which is why the stated 2457 baseline shows 57 skips. I installed Chromium vianode_modules/playwright-core/cli.js install chromiumso these tests actually execute. The +2 over #344 is exactly the two parameterized cases above.Cloud
No change needed.
webcmd-cloudimportsrunBrowserProgramfrom@agentrhq/webcmd/browser/runatsrc/browser/hosted-browser.ts:17, so hosted runs getwriteArtifactwhen the cloud bumps its pinned@agentrhq/webcmd(currently 0.7.2 on itsmain) — not bumped here.This PR adds a sandbox global and loosens a host-side argument guard; it does not change the
BrowserRunArtifactSinkinterface.webcmd-cloud/src/browser/run-artifact-sink.tsimplements exactly that interface —write({ filename, contentType, bytes }) => BrowserRunArtifactReceipt— and is unaffected. Its receipts already flow back through the sameoutput.artifactsarray, with acloud-artifact://locator instead ofbrowser-run://, which the new docs note.🤖 Generated with Claude Code