@opensteer/engine-playwright 0.8.5 → 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
@@ -1578,6 +1578,13 @@ async function waitForActionBoundary(input) {
1578
1578
  continue;
1579
1579
  }
1580
1580
  if (crossDocument) {
1581
+ if (!postLoadTrackerIsSettled(
1582
+ await input.readTrackerState(),
1583
+ DEFAULT_POST_LOAD_TRACKER_QUIET_WINDOW_MS
1584
+ )) {
1585
+ await delay(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
1586
+ continue;
1587
+ }
1581
1588
  return {
1582
1589
  trigger,
1583
1590
  crossDocument,
@@ -3985,6 +3992,7 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
3985
3992
  pageByPlaywrightPage = /* @__PURE__ */ new WeakMap();
3986
3993
  pendingPopupOpeners = /* @__PURE__ */ new WeakMap();
3987
3994
  preassignedPopupPageRefs = /* @__PURE__ */ new WeakMap();
3995
+ queuedPopupOpenedPages = /* @__PURE__ */ new WeakSet();
3988
3996
  actionSettler = createPlaywrightActionSettler({
3989
3997
  flushPendingPageTasks: (sessionRef) => this.flushPendingPageTasks(sessionRef),
3990
3998
  flushDomUpdateTask: (controller) => this.flushDomUpdateTask(controller),
@@ -4950,6 +4958,39 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
4950
4958
  throw normalizePlaywrightError(error, controller.pageRef);
4951
4959
  }
4952
4960
  }
4961
+ async evaluateFrame(input) {
4962
+ const frameState = this.requireFrame(input.frameRef);
4963
+ const controller = this.requirePage(frameState.pageRef);
4964
+ const startedAt = Date.now();
4965
+ const frame = this.requireLiveFrame(input.frameRef);
4966
+ try {
4967
+ const result = await withTimeout(
4968
+ frame.evaluate(
4969
+ ({ script, args }) => {
4970
+ const evaluated = (0, eval)(script);
4971
+ if (typeof evaluated === "function") {
4972
+ return evaluated(...args ?? []);
4973
+ }
4974
+ return evaluated;
4975
+ },
4976
+ {
4977
+ script: input.script,
4978
+ args: input.args ?? []
4979
+ }
4980
+ ),
4981
+ input.timeoutMs
4982
+ );
4983
+ return this.createStepResult(controller.sessionRef, controller.pageRef, startedAt, {
4984
+ frameRef: frameState.frameRef,
4985
+ documentRef: frameState.currentDocument.documentRef,
4986
+ documentEpoch: frameState.currentDocument.documentEpoch,
4987
+ events: this.drainQueuedEvents(controller.pageRef),
4988
+ data: result
4989
+ });
4990
+ } catch (error) {
4991
+ throw normalizePlaywrightError(error, controller.pageRef);
4992
+ }
4993
+ }
4953
4994
  async addInitScript(input) {
4954
4995
  if (!hasCapability(this.capabilities, "instrumentation.initScripts")) {
4955
4996
  throw unsupportedCapabilityError("instrumentation.initScripts");
@@ -5321,17 +5362,19 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5321
5362
  page.on(
5322
5363
  "popup",
5323
5364
  (popupPage) => this.runControllerEvent(controller, () => {
5324
- const popupPageRef = createPageRef(`playwright-${++this.pageCounter}`);
5325
- this.preassignedPopupPageRefs.set(popupPage, popupPageRef);
5326
- this.pendingPopupOpeners.set(popupPage, controller.pageRef);
5327
- 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(
5328
5374
  controller.pageRef,
5329
- this.createEvent({
5330
- kind: "popup-opened",
5331
- sessionRef: controller.sessionRef,
5332
- pageRef: popupPageRef,
5333
- openerPageRef: controller.pageRef
5334
- })
5375
+ popupPage,
5376
+ popupPageRef,
5377
+ controller.sessionRef
5335
5378
  );
5336
5379
  })
5337
5380
  );
@@ -5392,10 +5435,31 @@ var PlaywrightBrowserCoreEngine = class _PlaywrightBrowserCoreEngine {
5392
5435
  const openerController = pendingOpenerPageRef !== void 0 ? this.pages.get(pendingOpenerPageRef) : opener ? this.pageByPlaywrightPage.get(opener) : void 0;
5393
5436
  if (openerController) {
5394
5437
  controller.openerPageRef = openerController.pageRef;
5438
+ this.queuePopupOpenedEvent(
5439
+ openerController.pageRef,
5440
+ page,
5441
+ controller.pageRef,
5442
+ controller.sessionRef
5443
+ );
5395
5444
  }
5396
5445
  }
5397
5446
  return controller;
5398
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
+ }
5399
5463
  handleFrameAttached(controller, frameId, parentFrameId) {
5400
5464
  if (controller.framesByCdpId.has(frameId)) {
5401
5465
  return;