@opensteer/engine-playwright 0.8.6 → 0.8.7

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.
package/dist/index.cjs CHANGED
@@ -3992,6 +3992,7 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
3992
3992
  pageByPlaywrightPage = /* @__PURE__ */ new WeakMap();
3993
3993
  pendingPopupOpeners = /* @__PURE__ */ new WeakMap();
3994
3994
  preassignedPopupPageRefs = /* @__PURE__ */ new WeakMap();
3995
+ queuedPopupOpenedPages = /* @__PURE__ */ new WeakSet();
3995
3996
  actionSettler = createPlaywrightActionSettler({
3996
3997
  flushPendingPageTasks: (sessionRef) => this.flushPendingPageTasks(sessionRef),
3997
3998
  flushDomUpdateTask: (controller) => this.flushDomUpdateTask(controller),
@@ -5361,17 +5362,19 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5361
5362
  page.on(
5362
5363
  "popup",
5363
5364
  (popupPage) => this.runControllerEvent(controller, () => {
5364
- const popupPageRef = createPageRef(`playwright-${++this.pageCounter}`);
5365
- this.preassignedPopupPageRefs.set(popupPage, popupPageRef);
5366
- this.pendingPopupOpeners.set(popupPage, controller.pageRef);
5367
- this.queueEvent(
5365
+ const existingPopupController = this.pageByPlaywrightPage.get(popupPage);
5366
+ const popupPageRef = existingPopupController?.pageRef ?? createPageRef(`playwright-${++this.pageCounter}`);
5367
+ if (!existingPopupController) {
5368
+ this.preassignedPopupPageRefs.set(popupPage, popupPageRef);
5369
+ this.pendingPopupOpeners.set(popupPage, controller.pageRef);
5370
+ } else if (existingPopupController.openerPageRef === void 0) {
5371
+ existingPopupController.openerPageRef = controller.pageRef;
5372
+ }
5373
+ this.queuePopupOpenedEvent(
5368
5374
  controller.pageRef,
5369
- this.createEvent({
5370
- kind: "popup-opened",
5371
- sessionRef: controller.sessionRef,
5372
- pageRef: popupPageRef,
5373
- openerPageRef: controller.pageRef
5374
- })
5375
+ popupPage,
5376
+ popupPageRef,
5377
+ controller.sessionRef
5375
5378
  );
5376
5379
  })
5377
5380
  );
@@ -5432,10 +5435,31 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5432
5435
  const openerController = pendingOpenerPageRef !== void 0 ? this.pages.get(pendingOpenerPageRef) : opener ? this.pageByPlaywrightPage.get(opener) : void 0;
5433
5436
  if (openerController) {
5434
5437
  controller.openerPageRef = openerController.pageRef;
5438
+ this.queuePopupOpenedEvent(
5439
+ openerController.pageRef,
5440
+ page,
5441
+ controller.pageRef,
5442
+ controller.sessionRef
5443
+ );
5435
5444
  }
5436
5445
  }
5437
5446
  return controller;
5438
5447
  }
5448
+ queuePopupOpenedEvent(openerPageRef, popupPage, popupPageRef, sessionRef) {
5449
+ if (this.queuedPopupOpenedPages.has(popupPage)) {
5450
+ return;
5451
+ }
5452
+ this.queuedPopupOpenedPages.add(popupPage);
5453
+ this.queueEvent(
5454
+ openerPageRef,
5455
+ this.createEvent({
5456
+ kind: "popup-opened",
5457
+ sessionRef,
5458
+ pageRef: popupPageRef,
5459
+ openerPageRef
5460
+ })
5461
+ );
5462
+ }
5439
5463
  handleFrameAttached(controller, frameId, parentFrameId) {
5440
5464
  if (controller.framesByCdpId.has(frameId)) {
5441
5465
  return;