Repository navigation
Fix issues found after v1.1.0: context handshake, isolated iframes, waits across navigation, exposeFunction, drop-in alias - #132
Merged
Conversation
…exposeFunction Patches (puppeteer-core 25.14.0, playwright-core 1.64.1 and the Python driver build): - Call the handshake binding through `window`, not `self`: gbl.com and yara.com reassign `self`, and MetaMask's LavaMoat makes reading it throw, so no context id came back (#59, #100, #116; a Playwright regression from 1.52). - Puppeteer: create contexts lazily for late-attached frames in every patched mode, so alwaysIsolated reaches same-origin, srcdoc and hCaptcha iframes (#86); enableDisable takes the context of the right frame. - Puppeteer: re-run pending waitForFunction/waitForSelector after a navigation (#129). - exposeFunction works in the default mode (#69): re-add the CDP binding when a navigation commits, let the page side wait for it, and acquire a main world's context id when a binding call arrives before it is known. The page only ever sees the native binding. - Playwright: rename the UtilityScript binding so Error().stack no longer names it (#106). - Puppeteer: drop --enable-automation, which shows the automation infobar (#119). Tests: 7 new scenarios (29 per API family; all pass unpatched, all pass patched in the default mode), a multi-origin storageState restore (#81), a leaks suite (stack names, --enable-automation, what a page sees of the binding) and an opt-in nonchromium suite (Playwright on Firefox/WebKit, #105/#112/#126) that CI now installs and runs.
#74) With "puppeteer-core": "npm:rebrowser-puppeteer-core@V" in the wrapper, a project that also has upstream puppeteer@V (or playwright@V) got the alias deduped to the upstream core, and the drop-in silently ran unpatched code. The wrappers now depend on rebrowser-*-core under its real name, and build-packages rewrites the core's module specifiers in the wrapper code. The build fails if a specifier is left (including template literals and concatenations), if nothing matched, or if a rewritten subpath isn't exported by the core. The smoke suite gains an alias-collision gate: each drop-in is installed next to its upstream package and must export the patched core's objects, not upstream's.
The binding handshake that found a frame's main-world context left a native function with a random 10-20 character name on window (in the frame and its same-process iframes, two to four per page) and an init script per lookup. A page could spot those globals by their shape. The default mode now reads the frame's `document` in an isolated world, resolves that node again without a context (which lands in the frame's main world) and takes the context id from the remote object id; workers evaluate `this` in their only context. Nothing runs in the page. The binding handshake stays as a fallback for a Chrome that changes the object id format; it now removes its binding, deletes the global in the context it found and removes its init script. Playwright: the renamed UtilityScript binding is now a short name picked at random per process instead of a fixed one, so the stack frames don't carry a name only rebrowser-patches uses. The leaks suite gains a globals gate: a detector page samples window every 5 ms while the library evaluates, waits for selectors and reads the DOM (main frame, iframe, across a navigation). It fails on the published v1.1.0 packages (random-named globals) and passes here.
… position in Playwright - Puppeteer: by default add no sourceURL to evaluated code, so frames read "<anonymous>" like any injected script. The previous default, "app.js", was a fixed name only this patch uses. REBROWSER_PATCHES_SOURCE_URL=<name> still sets one; =0 keeps Puppeteer's "pptr:" URLs. - Playwright: besides the random helper name, shift the utility script down by a random number of lines per process, so the frames have no fixed position matching a renamed UtilityScript. - Both: warn once on the console (Node side) if the context lookup has to fall back to the binding handshake, since page scripts can notice that one.
This was referenced Oct 18, 2026
Closed
Closed
Closed
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.
Fixes for the bugs found while triaging the open issues against v1.1.0 (puppeteer-core 25.14.0, playwright-core 1.64.1, Python 1.64.0). Every fix has a regression test that fails on the published v1.1.0 packages and passes here.
Patch fixes
Context handshake on pages that redefine
self(failed: [rebrowser-patches] acquireContextId failed on chrome extensions pages #59, Bug: 'acquireContextId failed' on certain pages #100, Error: [rebrowser-patches] acquireContextId failed #116; Puppeteer and Playwright). The main-world handshake calledself[binding]. gbl.com and yara.com reassignself, and MetaMask's LavaMoat makes reading it throw, so no context id came back (acquireContextId failed/cannot get execution context id). For Playwright this was a regression from 1.52. The handshake now useswindow, which pages can't redefine.Puppeteer
alwaysIsolated: in-process iframes (Access to iframe content #86). Same-origin,srcdocand hCaptcha frames hung, because lazy context creation only ran inaddBindingmode. It now runs in every patched mode.enableDisablealso picks the context of the right frame now.Puppeteer
waitForFunction/waitForSelectoracross navigation (page.waitForFunction gets "lost" on navigation - original Puppeteer does not have this problem #129). After clearing the contexts on navigation, pending wait tasks are re-run, as stock Puppeteer does insetContext.page.exposeFunction()in the default mode (exposeFunction: globalThis[(prefix + name)] is not a function #69; Puppeteer and Playwright). WithoutRuntime.enable, Chrome drops CDP bindings on navigation (crbug.com/382473087). The fix has three parts:Calls during page load and after reloads work.
alwaysIsolatedstill can't support it, by design.Playwright
UtilityScriptin stack traces (Drop in Python rebrowser-playwright doesnt pass all rebrowser-patches tests #106). V8 namesevaluate()frames after the class binding, soError().stacksaidUtilityScript.evaluate. The binding is renamed (see below);REBROWSER_PATCHES_SOURCE_URL=0keeps the original.Puppeteer
--enable-automation(launchPersistentContext shows that it is being controlled by automated software #119). It showed the "Chrome is being controlled by automated test software" bar. It's dropped now, under the existingREBROWSER_PATCHES_WEBDRIVER_FIXswitch. Playwright 1.64 no longer passes it upstream.Nothing for pages to fingerprint
A detector-style audit compared stock, v1.1.0 and this build in default and
alwaysIsolatedmodes: globals sampled every 5 ms, stack traces taken from page getters, and function sources. It found three things, now fixed:Random-named globals (from v1.1.0 and earlier). The binding handshake left 2–4 native functions with random 10–20 character names on
windowper page, in iframes too. The default mode now finds a frame's main-world context without running anything in the page:documentin an isolated world.this.The old handshake is now only a fallback, with cleanup and a one-time Node-side warning. A new
leaksgate (globals) fails on v1.1.0 and passes here.Puppeteer
app.jsin stack traces. That fixed name was something only this patch uses. By default no sourceURL is added now, so frames are plain<anonymous>.Playwright helper name. It's a random 1–2 letter name per process, plus a random line offset, so there is no fixed name or position.
What remains is page-visible only when you opt into
exposeFunction/exposeBinding, which stock libraries already expose: the page-side function includes the wait-for-binding retry.Drop-in packages (#74)
rebrowser-puppeteer/rebrowser-playwrightnow depend onrebrowser-*-coreunder their real names. The npm alias they used before ("puppeteer-core": "npm:rebrowser-puppeteer-core@V") was deduped against upstreampuppeteer/playwrightof the same version, which silently gave the drop-in the unpatched core.build-packages.mjsrewrites the core's module specifiers in the wrapper code and fails if any remain, if nothing matched, or if a rewritten subpath isn't exported.Tests
scenarios: 7 new cases:waitForSelector-across-navigationiframe-srcdocpage-reassigns-selfpage-scuttles-selfiframe-churn-long-evaluateexposeFunction-called-on-loadexposeFunction-after-reloadUnpatched upstream passes 29/29. Patched default mode is now 29/29 for both libraries; only the documented
alwaysIsolatedlimits stay in the baselines.New
leakssuite: library names in stack traces,--enable-automationon the command line, what a page sees of the binding while parsing, and any global appearing onwindowwhile the library works. Unpatched builds and builds with the opt-out env var serve as controls.New
nonchromiumsuite (opt-in locally, on in CI): the patched Playwright build must still drive Firefox and WebKit ([feature request] WebKit support #105, [Bug]: _sessions is undefined in lib/server/frames.js:437 - this._page._delegate._sessions #112, How to ignore Patches for Webkit and Firefox? #126).smoke: newalias-collisiongate. Each drop-in is installed next to its upstream package and must load the patched core. The published 1.52.0 / 24.8.1 drop-ins fail it.Docs
README updates:
UtilityScriptand--enable-automation.RELEASING.md now describes the test gates.
No version bump here. These patches target the versions already published (25.14.0 / 1.64.1), so they ship either with the next upstream port or as an
X.Y.100re-release.