Memoize Playwright page target IDs - #355
Closed
ehfeng wants to merge 2 commits into
Closed
Conversation
ehfeng
force-pushed
the
codex/cus-580-memoize-page-target-ids
branch
from
August 24, 2026 23:05
1ceb4ab to
5782b01
Compare
ehfeng
marked this pull request as ready for review
August 24, 2026 23:06
rgarcia
force-pushed
the
codex/cus-580-memoize-page-target-ids
branch
from
August 25, 2026 01:37
5782b01 to
16d6b3a
Compare
Contributor
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.
Summary
Scope
This PR intentionally leaves browser-level CDP session consolidation unchanged. It isolates target-ID memoization and stale-cache recovery from that separate lifecycle refactor.
Stack
Validation
Note
Medium Risk
Changes which Playwright page the daemon binds for user code (foreground tab resolution) and adds caching that must stay correct across CDP reconnects and target replacement.
Overview
Adds
PageTargetIdCacheto memoize CDPtargetIdlookups per PlaywrightPage(WeakMap keys, shared in-flight discovery, optional refresh, and reset on browser disconnect/reconnect). Active-tab resolution now builds apageByTargetIdindex from the cache instead of opening a CDP session per page on every join, andpageForTabTargetmatches related targets via that map.resolveActivePageuses one browser CDP session per attempt, refreshes cached IDs on retries, bumps attempts to 3 with a 150ms delay between passes (for cross-origin tab target swaps), and logs unmatched active tab IDs on fallback.CI/build:
make test-runtimeruns Node tests for the cache; server unit workflow adds Node 22 and runs it; headful/headless Dockerfiles bundle the new module into the Playwright daemon esbuild step.Reviewed by Cursor Bugbot for commit 16d6b3a. Bugbot is set up for automated code reviews on this repo. Configure here.