Summary: context-less Runtime.evaluate (no executionContextId) resolves to the last-created execution context. On ad-heavy pages (OLX, Reddit) iframes are created after the main frame, so "last" is an ad iframe — CDP clients that read location/document without a contextId get ad URLs and stale-frame errors.
Symptoms (verified with a real CDP client against Camoufox 135 via foxbridge):
Runtime.evaluate {expression: "location.href"} returns https://adkernel.com/... or https://accounts.google.com/gsi/... while the browser is correctly on the target page.
-32000 Failed to find execution context with id = id-N — the cached context belongs to a frame destroyed during navigation.
Root cause: pkg/bridge/events.go tracks latestCtx = the most recent Juggler execution context created per session. Chrome's semantics are that context-less evaluate runs in the top frame; foxbridge's "latest wins" is the opposite of that, and ad-heavy pages are exactly where they diverge (ads load after the page).
Fix (implemented in https://github.com/lgwacker/foxbridge, commit a9020bd): track the main-frame execution context per Juggler session (AuxData.FrameID prefix mainframe) and prefer it for context-less evaluates, falling back to "latest" only until the main-frame context is known.
Evidence: with the fix, example.com, reddit.com/r/technology/ and olx.com.br search navigate and evaluate correctly on first try through the same harness; without it, the harness loops on id-N errors and reports Google/ad iframes as the current page.
Summary: context-less
Runtime.evaluate(noexecutionContextId) resolves to the last-created execution context. On ad-heavy pages (OLX, Reddit) iframes are created after the main frame, so "last" is an ad iframe — CDP clients that readlocation/documentwithout a contextId get ad URLs and stale-frame errors.Symptoms (verified with a real CDP client against Camoufox 135 via foxbridge):
Runtime.evaluate {expression: "location.href"}returnshttps://adkernel.com/...orhttps://accounts.google.com/gsi/...while the browser is correctly on the target page.-32000 Failed to find execution context with id = id-N— the cached context belongs to a frame destroyed during navigation.Root cause:
pkg/bridge/events.gotrackslatestCtx= the most recent Juggler execution context created per session. Chrome's semantics are that context-less evaluate runs in the top frame; foxbridge's "latest wins" is the opposite of that, and ad-heavy pages are exactly where they diverge (ads load after the page).Fix (implemented in https://github.com/lgwacker/foxbridge, commit
a9020bd): track the main-frame execution context per Juggler session (AuxData.FrameIDprefixmainframe) and prefer it for context-less evaluates, falling back to "latest" only until the main-frame context is known.Evidence: with the fix,
example.com,reddit.com/r/technology/andolx.com.brsearch navigate and evaluate correctly on first try through the same harness; without it, the harness loops onid-Nerrors and reports Google/ad iframes as the current page.