@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.d.cts CHANGED
@@ -1021,6 +1021,7 @@ declare class PlaywrightBrowserCoreEngine implements BrowserCoreEngine {
1021
1021
  private readonly pageByPlaywrightPage;
1022
1022
  private readonly pendingPopupOpeners;
1023
1023
  private readonly preassignedPopupPageRefs;
1024
+ private readonly queuedPopupOpenedPages;
1024
1025
  private readonly actionSettler;
1025
1026
  private pageCounter;
1026
1027
  private frameCounter;
@@ -1213,6 +1214,7 @@ declare class PlaywrightBrowserCoreEngine implements BrowserCoreEngine {
1213
1214
  private handleContextPage;
1214
1215
  private handleAttachedInitialPage;
1215
1216
  private initializePageController;
1217
+ private queuePopupOpenedEvent;
1216
1218
  private handleFrameAttached;
1217
1219
  private handleFrameDetached;
1218
1220
  private handleFrameNavigated;
package/dist/index.d.ts CHANGED
@@ -1021,6 +1021,7 @@ declare class PlaywrightBrowserCoreEngine implements BrowserCoreEngine {
1021
1021
  private readonly pageByPlaywrightPage;
1022
1022
  private readonly pendingPopupOpeners;
1023
1023
  private readonly preassignedPopupPageRefs;
1024
+ private readonly queuedPopupOpenedPages;
1024
1025
  private readonly actionSettler;
1025
1026
  private pageCounter;
1026
1027
  private frameCounter;
@@ -1213,6 +1214,7 @@ declare class PlaywrightBrowserCoreEngine implements BrowserCoreEngine {
1213
1214
  private handleContextPage;
1214
1215
  private handleAttachedInitialPage;
1215
1216
  private initializePageController;
1217
+ private queuePopupOpenedEvent;
1216
1218
  private handleFrameAttached;
1217
1219
  private handleFrameDetached;
1218
1220
  private handleFrameNavigated;
package/dist/index.js CHANGED
@@ -3990,6 +3990,7 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
3990
3990
  pageByPlaywrightPage = /* @__PURE__ */ new WeakMap();
3991
3991
  pendingPopupOpeners = /* @__PURE__ */ new WeakMap();
3992
3992
  preassignedPopupPageRefs = /* @__PURE__ */ new WeakMap();
3993
+ queuedPopupOpenedPages = /* @__PURE__ */ new WeakSet();
3993
3994
  actionSettler = createPlaywrightActionSettler({
3994
3995
  flushPendingPageTasks: (sessionRef) => this.flushPendingPageTasks(sessionRef),
3995
3996
  flushDomUpdateTask: (controller) => this.flushDomUpdateTask(controller),
@@ -5359,17 +5360,19 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5359
5360
  page.on(
5360
5361
  "popup",
5361
5362
  (popupPage) => this.runControllerEvent(controller, () => {
5362
- const popupPageRef = createPageRef(`playwright-${++this.pageCounter}`);
5363
- this.preassignedPopupPageRefs.set(popupPage, popupPageRef);
5364
- this.pendingPopupOpeners.set(popupPage, controller.pageRef);
5365
- this.queueEvent(
5363
+ const existingPopupController = this.pageByPlaywrightPage.get(popupPage);
5364
+ const popupPageRef = existingPopupController?.pageRef ?? createPageRef(`playwright-${++this.pageCounter}`);
5365
+ if (!existingPopupController) {
5366
+ this.preassignedPopupPageRefs.set(popupPage, popupPageRef);
5367
+ this.pendingPopupOpeners.set(popupPage, controller.pageRef);
5368
+ } else if (existingPopupController.openerPageRef === void 0) {
5369
+ existingPopupController.openerPageRef = controller.pageRef;
5370
+ }
5371
+ this.queuePopupOpenedEvent(
5366
5372
  controller.pageRef,
5367
- this.createEvent({
5368
- kind: "popup-opened",
5369
- sessionRef: controller.sessionRef,
5370
- pageRef: popupPageRef,
5371
- openerPageRef: controller.pageRef
5372
- })
5373
+ popupPage,
5374
+ popupPageRef,
5375
+ controller.sessionRef
5373
5376
  );
5374
5377
  })
5375
5378
  );
@@ -5430,10 +5433,31 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5430
5433
  const openerController = pendingOpenerPageRef !== void 0 ? this.pages.get(pendingOpenerPageRef) : opener ? this.pageByPlaywrightPage.get(opener) : void 0;
5431
5434
  if (openerController) {
5432
5435
  controller.openerPageRef = openerController.pageRef;
5436
+ this.queuePopupOpenedEvent(
5437
+ openerController.pageRef,
5438
+ page,
5439
+ controller.pageRef,
5440
+ controller.sessionRef
5441
+ );
5433
5442
  }
5434
5443
  }
5435
5444
  return controller;
5436
5445
  }
5446
+ queuePopupOpenedEvent(openerPageRef, popupPage, popupPageRef, sessionRef) {
5447
+ if (this.queuedPopupOpenedPages.has(popupPage)) {
5448
+ return;
5449
+ }
5450
+ this.queuedPopupOpenedPages.add(popupPage);
5451
+ this.queueEvent(
5452
+ openerPageRef,
5453
+ this.createEvent({
5454
+ kind: "popup-opened",
5455
+ sessionRef,
5456
+ pageRef: popupPageRef,
5457
+ openerPageRef
5458
+ })
5459
+ );
5460
+ }
5437
5461
  handleFrameAttached(controller, frameId, parentFrameId) {
5438
5462
  if (controller.framesByCdpId.has(frameId)) {
5439
5463
  return;