Skip to content

fix(browser): add URL-based fallback for extension relay tab matching#1999

Closed
jonit-dev wants to merge 1 commit intoopenclaw:mainfrom
jonit-dev:fix/extension-relay-tab-matching
Closed

fix(browser): add URL-based fallback for extension relay tab matching#1999
jonit-dev wants to merge 1 commit intoopenclaw:mainfrom
jonit-dev:fix/extension-relay-tab-matching

Conversation

@jonit-dev
Copy link
Copy Markdown
Contributor

Summary

When using the Chrome extension relay (profile=chrome), browser actions like snapshot fail with "tab not found" even though tabs correctly lists all attached tabs.

Root Cause

Playwright's newCDPSession(page) uses Target.attachToBrowserTarget to create CDP sessions for mapping pages to targetIds. Chrome's extension debugger API blocks this method with:

{"code":-32000,"message":"Not allowed"}

This causes findPageByTargetId() to fail for all pages.

Solution

Add a fallback in findPageByTargetId() that:

  1. Fetches targets from the HTTP /json/list endpoint
  2. Matches pages by URL (works for unique URLs)
  3. For duplicate URLs, uses index-based matching assuming consistent enumeration order

Testing

Tested locally with 9 attached Chrome tabs, including multiple tabs with the same URL. The fix correctly matches pages to targetIds.

Fixes #1998


🤖 This bug was discovered by Claude Code running inside Clawdbot, and the fix was developed and submitted with human oversight.

When using the Chrome extension relay, Playwright's newCDPSession() fails
because Target.attachToBrowserTarget is blocked by Chrome's extension API.
This prevents findPageByTargetId() from mapping Playwright pages to targetIds.

This fix adds a fallback that fetches targets from /json/list and matches
pages by URL when CDP sessions fail. For duplicate URLs, it uses index-based
matching assuming consistent enumeration order.

Fixes openclaw#1998
thewilloftheshadow added a commit that referenced this pull request Jan 26, 2026
Co-authored-by: João Paulo Furtado <jonit-dev@users.noreply.github.com>
@thewilloftheshadow
Copy link
Copy Markdown
Member

Squash-merged into main.

  • Squash commit: 5d2ef89
  • Included: URL-based fallback for extension relay tab matching + changelog entry (thanks)
  • Tests: pnpm lint && pnpm build && pnpm test (lint failed in existing src/line/* types)

@thewilloftheshadow
Copy link
Copy Markdown
Member

Closed after squash-merge to main (commit 5d2ef89).

jonit-dev added a commit to jonit-dev/clawdbot that referenced this pull request Jan 26, 2026
When using the Chrome extension relay (profile=chrome), CDP session-based
targetId resolution fails because Chrome blocks Target.attachToBrowserTarget.

This causes 'tab not found' errors when trying to interact with a page after
navigation, as the page cannot be re-resolved on subsequent requests.

This fix:
1. Adds a WeakRef cache that maps cdpUrl::targetId to Page objects
2. Checks the cache before attempting CDP/URL-based resolution
3. Caches successful resolutions for reuse in subsequent requests
4. Adds URL+title based fallback (similar to closed PR openclaw#1999) for cases
   where neither CDP nor cache works
5. Properly cleans up cache entries when pages close

The cache uses WeakRef to allow garbage collection of Page objects that
are no longer referenced elsewhere.

Fixes navigation + subsequent action workflows for extension relay profiles.
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Co-authored-by: João Paulo Furtado <jonit-dev@users.noreply.github.com>
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.

Browser extension relay: tab not found when multiple tabs have same URL

2 participants