Skip to content

fix(browser): use /devtools/page endpoint for all target types including iframes - #275

Open
I1Kuz wants to merge 2 commits into
cdpdriver:mainfrom
I1Kuz:iframe-fix
Open

fix(browser): use /devtools/page endpoint for all target types including iframes#275
I1Kuz wants to merge 2 commits into
cdpdriver:mainfrom
I1Kuz:iframe-fix

Conversation

@I1Kuz

@I1Kuz I1Kuz commented Sep 7, 2026

Copy link
Copy Markdown

Description

Problem

When Chrome creates targets for cross-origin iframes (Out-Of-Process Iframes / OOPIF), Browser._handle_target_update receives a cdp.target.TargetCreated event where target_info.type_ == "iframe".

The WebSocket connection URL was constructed as:

f"/devtools/{target_info.type_ or 'page'}"

This evaluated to ws://<host>:<port>/devtools/iframe/<target_id>. Attempting to connect to this target resulted in:

websockets.exceptions.InvalidStatus: server rejected WebSocket connection: HTTP 404

Chrome DevTools HTTP server only accepts connections under /devtools/page/<target_id> for all target types (as noted in the author's comment on that line, and as already implemented in Browser.update_targets).

Solution

  • Changed the WebSocket URL in Browser._handle_target_update to always use /devtools/page/<target_id>.
  • Allows Tab instances representing iframe targets to successfully connect via WebSocket and interact with elements inside cross-origin iframes.

Also consider exposing a property:

@property
def iframes(self) -> List[tab.Tab]:
    return [item for item in self.targets if getattr(item, "type_", None) == "iframe"]

and searching those targets in select_all(include_frames=True) when content_document is null due to cross-origin isolation.

Pre-merge Checklist

  • I have described my change in the section above.
  • I have ran the ./scripts/format.sh and ./scripts/lint.sh scripts. My code is properly formatted and has no linting errors.
  • I have ran uv run pytest and ensured all tests pass.
  • I have added my change to CHANGELOG.md under the [Unreleased] section.

@I1Kuz
I1Kuz requested a review from a team as a code owner September 7, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant