Skip to content

Runtime.evaluate without contextId resolves to last-created context (ad iframes on OLX/Reddit) #7

Description

@lgwacker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions