stagehand 4.4.1a0.dev1700__tar.gz → 4.4.1a0.dev1702__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/PKG-INFO +1 -1
  2. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/pyproject.toml +1 -1
  3. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/service-worker.js +150 -43
  4. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/README.md +0 -0
  5. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/__init__.py +0 -0
  6. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/blank.html +0 -0
  7. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/content-script.js +0 -0
  8. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/manifest.json +0 -0
  9. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/offscreen/service-worker-heartbeat.html +0 -0
  10. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/offscreen/service-worker-heartbeat.js +0 -0
  11. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/wake-service-worker.html +0 -0
  12. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_extension/wake-service-worker.js +0 -0
  13. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_generated/__init__.py +0 -0
  14. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_generated/input_types.py +0 -0
  15. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_generated/models.py +0 -0
  16. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_generated/protocol_version.py +0 -0
  17. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_sdk_identity.py +0 -0
  18. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/_validation.py +0 -0
  19. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browser.py +0 -0
  20. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browser_clipboard.py +0 -0
  21. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browser_context.py +0 -0
  22. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browserbase_connection.py +0 -0
  23. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browserbase_rpc.py +0 -0
  24. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browserbase_services.py +0 -0
  25. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browserbase_session.py +0 -0
  26. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/browserbase_transport.py +0 -0
  27. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/cdp_client.py +0 -0
  28. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/client_models.py +0 -0
  29. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/client_types.py +0 -0
  30. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/extension_assets.py +0 -0
  31. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/file_upload.py +0 -0
  32. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/locator.py +0 -0
  33. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/page.py +0 -0
  34. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/py.typed +0 -0
  35. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/response.py +0 -0
  36. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/rpc_client.py +0 -0
  37. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/stagehand.py +0 -0
  38. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/timeouts.py +0 -0
  39. {stagehand-4.4.1a0.dev1700 → stagehand-4.4.1a0.dev1702}/src/stagehand/webmcp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stagehand
3
- Version: 4.4.1a0.dev1700
3
+ Version: 4.4.1a0.dev1702
4
4
  Summary: Browserbase's SDK for building browser agents
5
5
  Keywords: ai,agent,ai-agent,browser,browser-agent,browser-automation,computer-use,headless,playwright,cdp,llm,automation,web-scraping,testing
6
6
  Author: Browserbase
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stagehand"
3
- version = "4.4.1a0.dev1700"
3
+ version = "4.4.1a0.dev1702"
4
4
  description = "Browserbase's SDK for building browser agents"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -66119,7 +66119,7 @@ var WebTracerProvider = class extends BasicTracerProvider {
66119
66119
  };
66120
66120
  var package_default = {
66121
66121
  name: "@browserbasehq/stagehand-extension",
66122
- version: "1.3.1-alpha-58a6cc14954503c96aba979ca76bcc0ecdf04bbf",
66122
+ version: "1.3.1-alpha-6f2686d792b7f5836b04754e0f6a44db39928592",
66123
66123
  "private": true,
66124
66124
  type: "module",
66125
66125
  scripts: {
@@ -66554,6 +66554,72 @@ var FrameRegistry = class {
66554
66554
  }
66555
66555
  };
66556
66556
  //#endregion
66557
+ //#region understudy/sessionNetworkCapture.ts
66558
+ /**
66559
+ * Captures one session's network events independently of page ownership.
66560
+ * Listeners are installed immediately; domain enablement belongs to the caller.
66561
+ * Events retain their arrival time and are buffered until a single consumer attaches.
66562
+ * The owner must dispose the capture when the session is no longer needed.
66563
+ */
66564
+ var SessionNetworkCapture = class {
66565
+ constructor(session) {
66566
+ this.session = session;
66567
+ this.pending = [];
66568
+ this.removeListeners = [];
66569
+ this.draining = false;
66570
+ this.disposed = false;
66571
+ try {
66572
+ this.listen("Network.requestWillBeSent");
66573
+ this.listen("Network.loadingFinished");
66574
+ this.listen("Network.loadingFailed");
66575
+ this.listen("Network.requestServedFromCache");
66576
+ this.listen("Network.responseReceived");
66577
+ this.listen("Page.frameStoppedLoading");
66578
+ } catch (error) {
66579
+ this.dispose();
66580
+ throw error;
66581
+ }
66582
+ }
66583
+ /** Deliver buffered events in order, then continue with live events. */
66584
+ attach(handlers) {
66585
+ if (this.disposed) throw new Error("Session network capture is disposed");
66586
+ if (this.handlers) throw new Error("Session network capture already has a consumer");
66587
+ this.handlers = handlers;
66588
+ this.drain();
66589
+ }
66590
+ /** Stop capturing and release both buffered events and the consumer. */
66591
+ dispose() {
66592
+ if (this.disposed) return;
66593
+ this.disposed = true;
66594
+ for (const remove of this.removeListeners) remove();
66595
+ this.removeListeners.length = 0;
66596
+ this.pending.length = 0;
66597
+ this.handlers = void 0;
66598
+ }
66599
+ listen(name) {
66600
+ const listener = (event) => {
66601
+ if (this.disposed) return;
66602
+ const receivedAt = Date.now();
66603
+ this.pending.push((handlers) => handlers[name](event, receivedAt));
66604
+ this.drain();
66605
+ };
66606
+ this.session.on(name, listener);
66607
+ this.removeListeners.push(() => this.session.off(name, listener));
66608
+ }
66609
+ drain() {
66610
+ const handlers = this.handlers;
66611
+ if (!handlers || this.draining || this.disposed) return;
66612
+ this.draining = true;
66613
+ let delivered = 0;
66614
+ try {
66615
+ while (!this.disposed && delivered < this.pending.length) this.pending[delivered++](handlers);
66616
+ } finally {
66617
+ this.pending.splice(0, delivered);
66618
+ this.draining = false;
66619
+ }
66620
+ }
66621
+ };
66622
+ //#endregion
66557
66623
  //#region types/private/network.ts
66558
66624
  var IGNORED_RESOURCE_TYPES = /* @__PURE__ */ new Set(["EventSource", "WebSocket"]);
66559
66625
  //#endregion
@@ -66579,12 +66645,18 @@ var NetworkManager = class {
66579
66645
  }
66580
66646
  /**
66581
66647
  * Begin tracking network traffic for a CDP session (top-level or OOPIF).
66582
- * Safe to call multiple times; duplicate registrations are ignored.
66648
+ * A supplied capture transfers ownership here; its domains must already be enabled.
66649
+ * Safe to call multiple times with the same session/capture.
66583
66650
  */
66584
- trackSession(session) {
66651
+ trackSession(session, pendingCapture) {
66652
+ if (pendingCapture && pendingCapture.session !== session) throw new Error("Network capture belongs to a different session");
66585
66653
  const sid = this.sessionKey(session);
66586
- if (this.sessions.has(sid)) return;
66587
- const onRequest = (evt) => {
66654
+ const existing = this.sessions.get(sid);
66655
+ if (existing) {
66656
+ if (pendingCapture && existing.capture !== pendingCapture) throw new Error("Network session already has a different capture");
66657
+ return;
66658
+ }
66659
+ const onRequest = (evt, receivedAt) => {
66588
66660
  if (!evt || !evt.requestId) return;
66589
66661
  const info = {
66590
66662
  sessionId: sid,
@@ -66593,7 +66665,7 @@ var NetworkManager = class {
66593
66665
  frameId: evt.frameId ?? void 0,
66594
66666
  loaderId: evt.loaderId ?? void 0,
66595
66667
  url: evt.request?.url,
66596
- timestamp: Date.now(),
66668
+ timestamp: receivedAt,
66597
66669
  resourceType: evt.type,
66598
66670
  documentRequest: evt.type === "Document"
66599
66671
  };
@@ -66601,7 +66673,7 @@ var NetworkManager = class {
66601
66673
  if (info.documentRequest && info.frameId) this.documentRequestsByFrame.set(info.frameId, info.requestKey);
66602
66674
  this.emitStart(info);
66603
66675
  };
66604
- const finish = (reqId) => {
66676
+ const finish = (reqId, receivedAt) => {
66605
66677
  const key = this.requestKey(sid, reqId);
66606
66678
  const stored = this.requests.get(key);
66607
66679
  if (stored?.frameId) this.documentRequestsByFrame.delete(stored.frameId);
@@ -66609,13 +66681,13 @@ var NetworkManager = class {
66609
66681
  sessionId: sid,
66610
66682
  requestId: reqId,
66611
66683
  requestKey: key,
66612
- timestamp: Date.now(),
66684
+ timestamp: receivedAt,
66613
66685
  documentRequest: false
66614
66686
  };
66615
66687
  this.requests.delete(key);
66616
66688
  this.emitFinish(info);
66617
66689
  };
66618
- const fail = (reqId) => {
66690
+ const fail = (reqId, receivedAt) => {
66619
66691
  const key = this.requestKey(sid, reqId);
66620
66692
  const stored = this.requests.get(key);
66621
66693
  if (stored?.frameId) this.documentRequestsByFrame.delete(stored.frameId);
@@ -66623,25 +66695,25 @@ var NetworkManager = class {
66623
66695
  sessionId: sid,
66624
66696
  requestId: reqId,
66625
66697
  requestKey: key,
66626
- timestamp: Date.now(),
66698
+ timestamp: receivedAt,
66627
66699
  documentRequest: false
66628
66700
  };
66629
66701
  this.requests.delete(key);
66630
66702
  this.emitFailure(info);
66631
66703
  };
66632
- const onFinished = (evt) => {
66704
+ const onFinished = (evt, receivedAt) => {
66633
66705
  if (!evt?.requestId) return;
66634
- finish(evt.requestId);
66706
+ finish(evt.requestId, receivedAt);
66635
66707
  };
66636
- const onFailed = (evt) => {
66708
+ const onFailed = (evt, receivedAt) => {
66637
66709
  if (!evt?.requestId) return;
66638
- fail(evt.requestId);
66710
+ fail(evt.requestId, receivedAt);
66639
66711
  };
66640
- const onResponse = (evt) => {
66712
+ const onResponse = (evt, receivedAt) => {
66641
66713
  if (!evt?.requestId) return;
66642
- if ((evt.response?.url ?? "").startsWith("data:")) finish(evt.requestId);
66714
+ if ((evt.response?.url ?? "").startsWith("data:")) finish(evt.requestId, receivedAt);
66643
66715
  };
66644
- const onFrameStopped = (evt) => {
66716
+ const onFrameStopped = (evt, receivedAt) => {
66645
66717
  if (!evt?.frameId) return;
66646
66718
  const key = this.documentRequestsByFrame.get(evt.frameId);
66647
66719
  if (!key) return;
@@ -66654,28 +66726,32 @@ var NetworkManager = class {
66654
66726
  this.documentRequestsByFrame.delete(evt.frameId);
66655
66727
  this.emitFinish({
66656
66728
  ...stored,
66657
- timestamp: Date.now()
66729
+ timestamp: receivedAt
66658
66730
  });
66659
66731
  };
66660
- session.on("Network.requestWillBeSent", onRequest);
66661
- session.on("Network.loadingFinished", onFinished);
66662
- session.on("Network.loadingFailed", onFailed);
66663
- session.on("Network.requestServedFromCache", onFinished);
66664
- session.on("Network.responseReceived", onResponse);
66665
- session.on("Page.frameStoppedLoading", onFrameStopped);
66666
- session.send("Network.enable").catch(() => {});
66667
- session.send("Page.enable").catch(() => {});
66732
+ const capture = pendingCapture ?? new SessionNetworkCapture(session);
66668
66733
  this.sessions.set(sid, {
66669
66734
  session,
66670
- detach: () => {
66671
- session.off("Network.requestWillBeSent", onRequest);
66672
- session.off("Network.loadingFinished", onFinished);
66673
- session.off("Network.loadingFailed", onFailed);
66674
- session.off("Network.requestServedFromCache", onFinished);
66675
- session.off("Network.responseReceived", onResponse);
66676
- session.off("Page.frameStoppedLoading", onFrameStopped);
66677
- }
66735
+ capture,
66736
+ detach: () => capture.dispose()
66678
66737
  });
66738
+ try {
66739
+ capture.attach({
66740
+ "Network.requestWillBeSent": onRequest,
66741
+ "Network.loadingFinished": onFinished,
66742
+ "Network.loadingFailed": onFailed,
66743
+ "Network.requestServedFromCache": onFinished,
66744
+ "Network.responseReceived": onResponse,
66745
+ "Page.frameStoppedLoading": onFrameStopped
66746
+ });
66747
+ } catch (error) {
66748
+ this.untrackSession(sid);
66749
+ throw error;
66750
+ }
66751
+ if (!pendingCapture) {
66752
+ session.send("Network.enable").catch(() => {});
66753
+ session.send("Page.enable").catch(() => {});
66754
+ }
66679
66755
  }
66680
66756
  /**
66681
66757
  * Stop tracking a session and discard any inflight bookkeeping owned by it.
@@ -68225,13 +68301,16 @@ var Page = class Page {
68225
68301
  * An OOPIF child session whose **main** frame id equals the parent iframe’s frameId
68226
68302
  * has been attached; adopt the session into this Page and seed ownership for its subtree.
68227
68303
  */
68228
- adoptOopifSession(childSession, childMainFrameId, onFrameTreeSeeded) {
68229
- if (this.disposed) return;
68304
+ adoptOopifSession(childSession, childMainFrameId, onFrameTreeSeeded, networkCapture) {
68305
+ if (this.disposed) {
68306
+ networkCapture?.dispose();
68307
+ return;
68308
+ }
68230
68309
  const previous = childSession.id ? this.sessions.get(childSession.id) : void 0;
68231
68310
  if (childSession.id) this.sessions.set(childSession.id, childSession);
68232
68311
  if (previous && previous !== childSession) this.stopWebMCPToolTracking(previous);
68233
68312
  for (const subscription of this.cdpEventSubscriptions) this.attachCDPEventSubscription(subscription, childSession);
68234
- this.networkManager.trackSession(childSession);
68313
+ this.networkManager.trackSession(childSession, networkCapture);
68235
68314
  if (this.extraHTTPHeaders) this.applyExtraHTTPHeadersToSession(childSession, this.extraHTTPHeaders).catch(() => {});
68236
68315
  this.applyInitScriptsToSession(childSession).catch(() => {});
68237
68316
  this.registry.adoptChildSession(childSession.id ?? "child", childMainFrameId);
@@ -71332,6 +71411,7 @@ var BrowserContext = class BrowserContext {
71332
71411
  this.mainFrameToTarget = /* @__PURE__ */ new Map();
71333
71412
  this.sessionOwnerPage = /* @__PURE__ */ new Map();
71334
71413
  this.frameOwnerPage = /* @__PURE__ */ new Map();
71414
+ this.pendingNetworkCaptures = /* @__PURE__ */ new Map();
71335
71415
  this.pendingOopifByMainFrame = /* @__PURE__ */ new Map();
71336
71416
  this.pendingOopifParentByMainFrame = /* @__PURE__ */ new Map();
71337
71417
  this.adoptedOopifSessionByFrame = /* @__PURE__ */ new Map();
@@ -71587,6 +71667,8 @@ var BrowserContext = class BrowserContext {
71587
71667
  close() {
71588
71668
  if (this.closePromise) return this.closePromise;
71589
71669
  this.closing = true;
71670
+ for (const { capture } of this.pendingNetworkCaptures.values()) capture.dispose();
71671
+ this.pendingNetworkCaptures.clear();
71590
71672
  const closing = Promise.resolve().then(async () => {
71591
71673
  try {
71592
71674
  await this.conn.close();
@@ -71673,7 +71755,7 @@ var BrowserContext = class BrowserContext {
71673
71755
  * - Resume the target only after listeners are wired.
71674
71756
  */
71675
71757
  async onAttachedToTarget(info, sessionId) {
71676
- if (await this.closePopupIfBlockedByDomainPolicy(info, "attached")) return;
71758
+ if (await this.closePopupIfBlockedByDomainPolicy(info, "attached") || this.closing) return;
71677
71759
  if (isNonWebTarget(info)) {
71678
71760
  const session = this.conn.getSession(sessionId);
71679
71761
  if (session) await session.send("Runtime.runIfWaitingForDebugger").catch(() => {});
@@ -71692,6 +71774,11 @@ var BrowserContext = class BrowserContext {
71692
71774
  resumed = true;
71693
71775
  await session.send("Runtime.runIfWaitingForDebugger").catch(() => {});
71694
71776
  };
71777
+ const networkCapture = isTopLevelPage(info) ? void 0 : new SessionNetworkCapture(session);
71778
+ if (networkCapture) this.pendingNetworkCaptures.set(sessionId, {
71779
+ targetId: info.targetId,
71780
+ capture: networkCapture
71781
+ });
71695
71782
  const queuePreResume = (method, params, match) => {
71696
71783
  return {
71697
71784
  dispatched: this.conn.waitForSessionDispatch(sessionId, method, match).then(() => true).catch(() => false),
@@ -71700,6 +71787,7 @@ var BrowserContext = class BrowserContext {
71700
71787
  };
71701
71788
  const initScriptOps = [];
71702
71789
  const corePreResumeOps = [
71790
+ ...networkCapture ? [queuePreResume("Network.enable")] : [],
71703
71791
  queuePreResume("Page.enable"),
71704
71792
  queuePreResume("Runtime.enable"),
71705
71793
  queuePreResume("Target.setAutoAttach", {
@@ -71711,7 +71799,7 @@ var BrowserContext = class BrowserContext {
71711
71799
  const headerPreResumeOps = [];
71712
71800
  if (this.extraHttpHeaders) {
71713
71801
  const headers = { ...this.extraHttpHeaders };
71714
- headerPreResumeOps.push(queuePreResume("Network.enable"));
71802
+ if (!networkCapture) headerPreResumeOps.push(queuePreResume("Network.enable"));
71715
71803
  headerPreResumeOps.push(queuePreResume("Network.setExtraHTTPHeaders", { headers }));
71716
71804
  }
71717
71805
  if (this.initScripts.length) for (const source of this.initScripts) initScriptOps.push(queuePreResume("Page.addScriptToEvaluateOnNewDocument", {
@@ -71731,6 +71819,7 @@ var BrowserContext = class BrowserContext {
71731
71819
  Promise.all(initScriptOps.map((op) => op.response))
71732
71820
  ]);
71733
71821
  if (!preResumeDispatched || !resumedDispatched || !resumedOk) {
71822
+ this.disposePendingNetworkCapture(sessionId);
71734
71823
  if (isTopLevelPage(info)) {
71735
71824
  this.recordPageCreationFailure(info.targetId, /* @__PURE__ */ new Error("Failed target pre-resume setup ordering"), "Failed target pre-resume setup ordering");
71736
71825
  this.logger.debug("Failed target pre-resume setup ordering", {
@@ -71784,6 +71873,7 @@ var BrowserContext = class BrowserContext {
71784
71873
  }
71785
71874
  try {
71786
71875
  const { frameTree } = await session.send("Page.getFrameTree");
71876
+ if (this.closing || this.conn.getSession(sessionId) !== session) return;
71787
71877
  const childMainId = frameTree.frame.id;
71788
71878
  const parentFrameId = frameTree.frame.parentId;
71789
71879
  const owner = this.findPageOwningFrame(childMainId) ?? (parentFrameId ? this.findPageOwningFrame(parentFrameId) : void 0);
@@ -71794,7 +71884,9 @@ var BrowserContext = class BrowserContext {
71794
71884
  this.pendingOopifByMainFrame.set(childMainId, sessionId);
71795
71885
  if (parentFrameId) this.pendingOopifParentByMainFrame.set(childMainId, parentFrameId);
71796
71886
  }
71797
- } catch {}
71887
+ } catch {
71888
+ this.disposePendingNetworkCapture(sessionId);
71889
+ }
71798
71890
  } finally {
71799
71891
  await resume();
71800
71892
  }
@@ -71811,15 +71903,26 @@ var BrowserContext = class BrowserContext {
71811
71903
  for (const p of this.pagesByTarget.values()) if (p.listAllFrameIds().includes(frameId)) return p;
71812
71904
  }
71813
71905
  adoptOopif(owner, session, childMainId) {
71814
- owner.adoptOopifSession(session, childMainId, () => {
71815
- this.adoptPendingOopifsByParent();
71816
- });
71906
+ const pending = this.pendingNetworkCaptures.get(session.id);
71907
+ this.pendingNetworkCaptures.delete(session.id);
71908
+ try {
71909
+ owner.adoptOopifSession(session, childMainId, () => {
71910
+ this.adoptPendingOopifsByParent();
71911
+ }, pending?.capture);
71912
+ } catch (error) {
71913
+ pending?.capture.dispose();
71914
+ throw error;
71915
+ }
71817
71916
  this.adoptedOopifSessionByFrame.set(childMainId, session.id);
71818
71917
  this.sessionOwnerPage.set(session.id, owner);
71819
71918
  this.frameOwnerPage.set(childMainId, owner);
71820
71919
  this.installFrameEventBridges(session.id, owner);
71821
71920
  executionContexts.waitForMainWorld(session, childMainId).catch(() => {});
71822
71921
  }
71922
+ disposePendingNetworkCapture(sessionId) {
71923
+ this.pendingNetworkCaptures.get(sessionId)?.capture.dispose();
71924
+ this.pendingNetworkCaptures.delete(sessionId);
71925
+ }
71823
71926
  removePendingOopif(frameId) {
71824
71927
  this.pendingOopifByMainFrame.delete(frameId);
71825
71928
  this.pendingOopifParentByMainFrame.delete(frameId);
@@ -71834,6 +71937,7 @@ var BrowserContext = class BrowserContext {
71834
71937
  const parentId = this.pendingOopifParentByMainFrame.get(frameId);
71835
71938
  if (!pageFrameIds.has(frameId) && (!parentId || !pageFrameIds.has(parentId))) continue;
71836
71939
  pageFrameIds.add(frameId);
71940
+ this.disposePendingNetworkCapture(this.pendingOopifByMainFrame.get(frameId));
71837
71941
  this.removePendingOopif(frameId);
71838
71942
  removed = true;
71839
71943
  }
@@ -71852,6 +71956,7 @@ var BrowserContext = class BrowserContext {
71852
71956
  const childSessionId = this.pendingOopifByMainFrame.get(childMainId);
71853
71957
  const child = childSessionId ? this.conn.getSession(childSessionId) : void 0;
71854
71958
  if (!child) {
71959
+ if (childSessionId) this.disposePendingNetworkCapture(childSessionId);
71855
71960
  this.removePendingOopif(childMainId);
71856
71961
  continue;
71857
71962
  }
@@ -71911,6 +72016,7 @@ var BrowserContext = class BrowserContext {
71911
72016
  * - Drop any staged child for this session.
71912
72017
  */
71913
72018
  onDetachedFromTarget(sessionId, targetId) {
72019
+ this.disposePendingNetworkCapture(sessionId);
71914
72020
  const closingPage = targetId ? this.pagesByTarget.get(targetId) : void 0;
71915
72021
  if (closingPage) this.removePendingOopifsForPage(closingPage);
71916
72022
  const owner = this.sessionOwnerPage.get(sessionId);
@@ -71928,6 +72034,7 @@ var BrowserContext = class BrowserContext {
71928
72034
  * Cleanup a top-level Page by target id, removing its root and staged children.
71929
72035
  */
71930
72036
  cleanupByTarget(targetId) {
72037
+ for (const [sessionId, pending] of this.pendingNetworkCaptures) if (pending.targetId === targetId) this.disposePendingNetworkCapture(sessionId);
71931
72038
  this.recordPageCreationFailure(targetId, /* @__PURE__ */ new Error(`Target closed before page registration (${targetId})`), "Target closed before page registration");
71932
72039
  const page = this.pagesByTarget.get(targetId);
71933
72040
  if (!page) return;