fix(cdp): allocate fresh execution context ids per isolated world (#192) (#200)

Page.createIsolatedWorld and do_navigate both hardcoded context id 100
  for every isolated world emission. After the second navigation Playwright
  expected a fresh incrementing id (101, 102) while obscura kept re-using
  100. Runtime.evaluate then failed with 'Cannot find context with
  specified id: 101' because the id was never registered in
  valid_context_ids and the client's bookkeeping had diverged from the
  server's.

  Added next_isolated_context_id counter on CdpContext (starts at 100) and
  a next_isolated_context() helper that claims an id, registers it in
  valid_context_ids, and increments. Both call sites now use it.
This commit is contained in:
SGavrl authored and GitHub committed 2026-05-29 17:11:10 +00:00
1 parent 191c5ac7a2
commit 682431f766
2 files changed
+46 -15

No files matched your search

+18
View File
@@ -35,6 +35,14 @@ pub struct CdpContext {
// "Cannot find context with specified id" CDP error and unblocking the
// Playwright locator path described in issue #51.
pub valid_context_ids: HashSet<i64>,
// Monotonic counter for isolated-world execution context ids. Issue #192:
// both `Page.createIsolatedWorld` and `do_navigate` used to hardcode id
// 100, so re-creating a context (e.g. Playwright opening a second page or
// re-navigating) silently emitted the same id twice and the client's
// bookkeeping diverged from the server's. Each fresh isolated context now
// claims and increments from this counter so the ids real Chrome would
// emit (incrementing, never reused) are mirrored.
pub next_isolated_context_id: i64,
pub fetch_intercept: FetchInterceptState,
pub intercept_tx: Option<tokio::sync::mpsc::UnboundedSender<InterceptedRequest>>,
}
@@ -124,9 +132,19 @@ impl CdpContext {
intercept_tx: None,
isolated_worlds: Vec::new(),
valid_context_ids,
next_isolated_context_id: 100,
}
}
/// Claim the next isolated-world execution context id and register it as
/// valid for `Runtime.evaluate`/`callFunctionOn`. Issue #192.
pub fn next_isolated_context(&mut self) -> i64 {
let id = self.next_isolated_context_id;
self.next_isolated_context_id += 1;
self.valid_context_ids.insert(id);
id
}
pub fn create_page(&mut self) -> String {
self.page_counter += 1;
let page_id = format!("page-{}", self.page_counter);