Repository navigation
Own browser service M1b: injected script, selectors, reads, evaluate, snapshot (#113) - #124
Conversation
…ected script extracted from it The vendor's embedded InjectedScript (BS:54564-54565) matches 1.59.x (its property set equals 1.59.1's generated source but for the wrapper); 1.59.0 and 1.59.1 ship the same script. scripts/extract-injected-script.mjs refuses a range pin or an installed version other than the pin, and writes vendor/injected-script.js (the generated source wrapped as the PlaywrightInjected global, Apache-2.0 notice and NOTICE) and VERSION.
…esolution injected.mjs ports Pf's installation half: Playwright's InjectedScript in each frame's isolated world cua-browser-injected (never the page's world), installed on first use, dropped on navigation, cleared contexts, detached frames and tabs, and made again once when an evaluation finds its world gone or the script missing; the vendor's credential-field check is attached as JY does. Every CDP call carries the command's Deadline. selectors.mjs ports Pf's resolution half: selector scope and frame entry in the page, cross-origin and out-of-process frames entered through CDP on their own world and target, strict mode with the vendor's visible fallback and sentence, polling every 100 ms until the Deadline with strict-mode violations and dialog_open final. Interface: resolve/resolveAll -> ElementHandle, evaluateOnSelector, evaluateOnSelectorAll, evaluateInFrame, handle.evaluate. BrowserSession carries one engine per controller; Deadline keeps its budget. Tests drive the real CdpController against a fake Chrome whose worlds run the service's expressions in node:vm.
…9.1, the unminified install cost)
…eps its scope when empty
…d selectors
- A world made or filled while a navigation or cleared context invalidated
worlds is not kept, and an installation that finds its world gone forgets
it; installation runs inside the evaluation's one-time recovery, so a dead
context is never reused until the deadline.
- Every by-value path releases the remote objects a page exception holds
(installation, evaluateValue, evaluateOnSelector, handle.evaluate).
- A zero budget is one attempt whose dispatches get the 3 s action budget
(the controller's ruling), for resolution, handles and frame evaluation.
- resolveAll returns {handles, target, frameId, oopifFrameChain, selector,
documentBackendNodeId}: the frame the query ran in also when nothing
matched, same-process frames included, for evaluateAll to bind to.
…no-replay rule, the aria snapshot and the visible-DOM listing reads.mjs, evaluate.mjs, snapshot.mjs and visible-dom.mjs registered in COMMAND_HANDLERS; tab_ax_get_state and tab_ax_action refused as an unavailable capability; the fake page world resolves nodes into object groups and evaluates in the page's own world without a context id.
…ain; reads/frames, reads/zero-budget and evaluate/budget; expected differences for main-world evaluate and the 120 s budget
… evaluated scripts; zero-budget and late-completion oracles corrected after the first live run
…the extension relays as JSON by its message
…vendor control for the createBrowserTab setup, the cua run, 0 unexpected differences)
…1c corrects the cua evaluate text
…ect projection with explicit browser-type adapters; one attempt budget across an evaluate's preparation and script; the comparator masks positions on stack frame lines only)
…dor's read-only scope wraps as its wrappers and builders do (collections, attributes, data sets, time ranges, tracks, validity, styles, media lists, CSS rules and sheets, the font set, the location)
…ice, collections read only up to the limit (a throwing or endless one gives its prefix), and the visible-DOM listing releases a page exception's remote object
…ad-only attribute (null for a credential field's value); evaluate/attributes parity case
…dor's deadline sentence, which vary by run
…review fixes (fresh vendor and cua runs with evaluate/attributes; 0 unexpected differences)
…sible-DOM page is owed by M3 or M5
…the output (no read or iterator step past the limit) and the projection writes past page setters with a defineProperty captured before the script
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a55d0607af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!roomLeft(output)) return; | ||
| for (const child of childFrames) { | ||
| if (!roomLeft(output) || Date.now() >= childFrameDeadline) break; | ||
| const clip = clipInside(child.rect, viewportClip); |
There was a problem hiding this comment.
Scale the iframe clip into child coordinates
When an iframe is CSS-scaled or its rendered rectangle differs from its clientWidth/clientHeight, child.rect is expressed in the parent’s rendered coordinates, but the result of clipInside is passed directly into the child document as CSS viewport coordinates. For example, a 300px-wide iframe rendered at 50% scale produces a 150px clip, causing visible child elements beyond x=150 to be omitted from get_visible_dom() and therefore unavailable by node ID. Convert the intersection using the recorded child.size (and account for the iframe content-box offset) before listing the child frame.
Useful? React with 👍 / 👎.
| const injected = second ?? first; | ||
| const root = second ? first : (document.body || document.documentElement); | ||
| if (!root) return {full: '', iframeDepths: {}, iframeRefs: []}; | ||
| const snapshot = injected.incrementalAriaSnapshot(root, {mode: 'ai'}); |
There was a problem hiding this comment.
Redact protected values before rendering the snapshot
On a login or contact form with a populated password, username, email, OTP, or phone field, this call emits the field's current value into dom_snapshot: the vendored toAriaNode explicitly assigns result.children = [element.value] for inputs and textareas (vendor/injected-script.js:3987-3989), while incrementalAriaSnapshot never consults the installed isProtectedCredentialField hook. Because DOM snapshots are also fetched automatically when a browser tab is created, this exposes credentials to the model even without an explicit value read; sanitize protected textbox nodes before returning the snapshot.
Useful? React with 👍 / 👎.
| }, | ||
|
|
||
| async playwright_locator_text_content(params, session) { | ||
| return {value: (await readOne(params, session, element => element.textContent)).result}; |
There was a problem hiding this comment.
Withhold protected textarea text from locator reads
When a protected <textarea> contains an initial/default credential value, that value is stored in its text node, so returning element.textContent exposes it despite the module's stated credential-field protection. The same leak exists in inner_text, all_text_contents, and both text fields produced by read_all; those paths should consult injected.isProtectedCredentialField(element) just as get_attribute('value') and the visible-DOM implementation do.
Useful? React with 👍 / 👎.
| return `async function (...__cuaArguments) { | ||
| const __name = (target) => target; | ||
| ${binding} | ||
| const __cuaIntrinsics = {defineProperty: Object.defineProperty}; |
There was a problem hiding this comment.
Capture serializer intrinsics before running the page script
When the evaluated script mutates a serializer dependency before returning—for example, replacing Object.prototype.hasOwnProperty or WeakSet—projectResult resolves those globals only after the awaited script completes, so an ordinary object can incorrectly project as {} or a cyclic value can recurse until evaluation fails. Capturing only Object.defineProperty does not provide the promised bounded projection; capture every intrinsic used by projectResult before invoking user code (and pass those captured operations into the serializer).
Useful? React with 👍 / 👎.
| }; | ||
| const visibleRect = element => { | ||
| const style = window.getComputedStyle(element); | ||
| if (style.visibility !== 'visible' || style.display === 'none' || style.pointerEvents === 'none' || Number(style.opacity) <= 0.01) return null; |
There was a problem hiding this comment.
Exclude descendants of transparent ancestors
When an interactive element is inside a container with opacity: 0, its own computed opacity remains 1, and it can still have non-empty client rects, so this predicate lists it even though a person cannot see it. This also causes invisible iframe descendants to be traversed. Account for opacity on the composed ancestor chain (including shadow hosts) before assigning a visible-DOM node ID.
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
M1b of the own browser service (#113, child 1 of #114): the injected script, selector resolution, locator reads, main-world evaluate with the no-replay rule, the aria snapshot and the visible-DOM listing. Spec:
docs/doperpowers/specs/2026-10-13-own-browser-service-design.md(Plan of Work M1b; execution rulings in its Decision Log and Surprises dated 2026-10-13). The default staysvendor.What changed
playwright-corepinned at 1.59.1 (devDependency);scripts/extract-injected-script.mjsextracts Playwright's InjectedScript (Apache-2.0) intosrc/browser-service/vendor/injected-script.jswith itsVERSION, refusing a version mismatch.injected.mjs: per-frame install in the isolated worldcua-browser-injected, recovery from navigation races and context loss, remote objects released on every path.selectors.mjs: the resolution half of the vendor's locator class (strictness and its sentence, frame traversal, polling to the deadline,dialog_opennever retried; an explicittimeoutMs: 0is one attempt bounded by 3 s);resolveAllkeeps its frame scope when nothing matches.reads.mjs,evaluate.mjs(main world; a dispatched user script is never sent again; the vendor's result projection with adapters for every vendor-wrapped browser type, a bareAttrincluded; limits re-applied on the trusted side and collections read by a bounded reader that page prototypes cannot steer),snapshot.mjs(aria snapshot, frames stitched, the vendor's flattening),visible-dom.mjs(20,000 chars / 200 elements, fixed).cua.createBrowserTabagain (vendor control diff 0); new casesreads/frames,reads/zero-budget,evaluate/budget,evaluate/attributes; expected differences for main-world evaluate and the 120 s budget; the comparator masks positions only in anonymous stack frames.Validation Evidence
HOME=/tmp/cua-scratch-home npm test→# pass 1419,# fail 0,# skipped 6(skips fell from 37 because installing playwright-core createsnode_modules, so the ws-dependent tests run);npm run test:mods→32 pass;claude plugin validate .→✔ Validation passed with warnings(the known warning).ssfs, parity clone),docs/evidence/2026-10-13-own-browser-service-parity/m1b-diff.txt:diff vendor-m1b-2 cua-m1b-2 --scenarios 'tabs/*.mjs,examples/*.mjs,reads/*.mjs,evaluate/*.mjs,input/ax-disabled.mjs'→0 unexpected differences (20 cases, 70 cells, 7 expected)diff vendor-1 cua-m1b-2(M1a+M1b cases) →0 unexpected differences (16 cases, 57 cells, 6 expected);diff vendor-1 vendor-m1b-2→0 differences (16 cases, 57 cells)CUA_BROWSER_SERVICE=cua: thedocument.titleevaluate returnschangedandtab.title()readschanged; the context-loss evaluate fails with the interruption sentence, the POST counter reads 1, and the session stays usable.doperpowers:reviewer-high: P1 (page-controlled projection bounds), two P2 (unbounded collection traversal, visible-DOM exception leak), then one P2 in the bounded reader; all fixed; final verdict "correct", no material findings.Residue