@opensteer/engine-abp 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
@@ -770,6 +770,12 @@ interface BrowserInspector {
770
770
  readonly args?: readonly unknown[];
771
771
  readonly timeoutMs?: number;
772
772
  }): Promise<StepResult<unknown>>;
773
+ evaluateFrame(input: {
774
+ readonly frameRef: FrameRef;
775
+ readonly script: string;
776
+ readonly args?: readonly unknown[];
777
+ readonly timeoutMs?: number;
778
+ }): Promise<StepResult<unknown>>;
773
779
  }
774
780
  interface SessionTransportExecutor {
775
781
  readonly capabilities: Readonly<BrowserCapabilities>;
@@ -1170,6 +1176,12 @@ declare class AbpBrowserCoreEngine implements BrowserCoreEngine {
1170
1176
  readonly args?: readonly unknown[];
1171
1177
  readonly timeoutMs?: number;
1172
1178
  }): Promise<StepResult<unknown>>;
1179
+ evaluateFrame(input: {
1180
+ readonly frameRef: FrameRef;
1181
+ readonly script: string;
1182
+ readonly args?: readonly unknown[];
1183
+ readonly timeoutMs?: number;
1184
+ }): Promise<StepResult<unknown>>;
1173
1185
  addInitScript(_input: BrowserInitScriptInput): Promise<BrowserInitScriptRegistration>;
1174
1186
  registerRoute(_input: BrowserRouteRegistrationInput): Promise<BrowserRouteRegistration>;
1175
1187
  executeRequest(input: {
@@ -1221,6 +1233,7 @@ declare class AbpBrowserCoreEngine implements BrowserCoreEngine {
1221
1233
  private requireSession;
1222
1234
  private requirePage;
1223
1235
  private requireFrame;
1236
+ private ensureFrameExecutionContext;
1224
1237
  private requireDocument;
1225
1238
  private cleanupPageController;
1226
1239
  private throwBackgroundError;
package/dist/index.d.ts CHANGED
@@ -770,6 +770,12 @@ interface BrowserInspector {
770
770
  readonly args?: readonly unknown[];
771
771
  readonly timeoutMs?: number;
772
772
  }): Promise<StepResult<unknown>>;
773
+ evaluateFrame(input: {
774
+ readonly frameRef: FrameRef;
775
+ readonly script: string;
776
+ readonly args?: readonly unknown[];
777
+ readonly timeoutMs?: number;
778
+ }): Promise<StepResult<unknown>>;
773
779
  }
774
780
  interface SessionTransportExecutor {
775
781
  readonly capabilities: Readonly<BrowserCapabilities>;
@@ -1170,6 +1176,12 @@ declare class AbpBrowserCoreEngine implements BrowserCoreEngine {
1170
1176
  readonly args?: readonly unknown[];
1171
1177
  readonly timeoutMs?: number;
1172
1178
  }): Promise<StepResult<unknown>>;
1179
+ evaluateFrame(input: {
1180
+ readonly frameRef: FrameRef;
1181
+ readonly script: string;
1182
+ readonly args?: readonly unknown[];
1183
+ readonly timeoutMs?: number;
1184
+ }): Promise<StepResult<unknown>>;
1173
1185
  addInitScript(_input: BrowserInitScriptInput): Promise<BrowserInitScriptRegistration>;
1174
1186
  registerRoute(_input: BrowserRouteRegistrationInput): Promise<BrowserRouteRegistration>;
1175
1187
  executeRequest(input: {
@@ -1221,6 +1233,7 @@ declare class AbpBrowserCoreEngine implements BrowserCoreEngine {
1221
1233
  private requireSession;
1222
1234
  private requirePage;
1223
1235
  private requireFrame;
1236
+ private ensureFrameExecutionContext;
1224
1237
  private requireDocument;
1225
1238
  private cleanupPageController;
1226
1239
  private throwBackgroundError;
package/dist/index.js CHANGED
@@ -1571,6 +1571,13 @@ async function waitForActionBoundary(input) {
1571
1571
  continue;
1572
1572
  }
1573
1573
  if (crossDocument) {
1574
+ if (!postLoadTrackerIsSettled(
1575
+ await input.readTrackerState(),
1576
+ DEFAULT_POST_LOAD_TRACKER_QUIET_WINDOW_MS
1577
+ )) {
1578
+ await delay(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
1579
+ continue;
1580
+ }
1574
1581
  return {
1575
1582
  trigger,
1576
1583
  crossDocument,
@@ -1718,6 +1725,7 @@ var PAGE_CDP_METHOD_ALLOWLIST = /* @__PURE__ */ new Set([
1718
1725
  "IndexedDB.requestDatabase",
1719
1726
  "IndexedDB.requestDatabaseNames",
1720
1727
  "Page.addScriptToEvaluateOnNewDocument",
1728
+ "Page.createIsolatedWorld",
1721
1729
  "Page.enable",
1722
1730
  "Page.getFrameTree",
1723
1731
  "Page.getLayoutMetrics",
@@ -2402,12 +2410,11 @@ function createAbpActionSettler(context) {
2402
2410
  }
2403
2411
  await beginTrackerObservation(controller);
2404
2412
  const tracker = await readTrackerState(controller);
2413
+ const mainFrameUrl = controller.mainFrameRef === void 0 ? void 0 : controller.framesByCdpId.get(controller.mainFrameRef)?.currentDocument.url;
2405
2414
  return {
2406
2415
  pageRef: controller.pageRef,
2407
2416
  documentRef,
2408
- ...controller.mainFrameRef === void 0 ? {} : {
2409
- url: controller.framesByCdpId.get(controller.mainFrameRef)?.currentDocument.url
2410
- },
2417
+ ...mainFrameUrl === void 0 ? {} : { url: mainFrameUrl },
2411
2418
  ...tracker === void 0 ? {} : { tracker: capturePostLoadTrackerSnapshot(tracker) }
2412
2419
  };
2413
2420
  }
@@ -5677,6 +5684,46 @@ var AbpBrowserCoreEngine = class _AbpBrowserCoreEngine {
5677
5684
  throw normalizeAbpError(error, controller.pageRef);
5678
5685
  }
5679
5686
  }
5687
+ async evaluateFrame(input) {
5688
+ const frame = this.requireFrame(input.frameRef);
5689
+ const controller = this.requirePage(frame.pageRef);
5690
+ const startedAt = Date.now();
5691
+ try {
5692
+ const executionContextId = await withTimeout(
5693
+ this.ensureFrameExecutionContext(controller, frame.cdpFrameId),
5694
+ input.timeoutMs
5695
+ );
5696
+ const serialized = JSON.stringify({
5697
+ script: input.script,
5698
+ args: input.args ?? []
5699
+ });
5700
+ const evaluated = await withTimeout(
5701
+ controller.cdp.send("Runtime.evaluate", {
5702
+ contextId: executionContextId,
5703
+ expression: `(() => {
5704
+ const input = ${serialized};
5705
+ const evaluated = (0, eval)(input.script);
5706
+ if (typeof evaluated === "function") {
5707
+ return evaluated(...(input.args ?? []));
5708
+ }
5709
+ return evaluated;
5710
+ })()`,
5711
+ returnByValue: true,
5712
+ awaitPromise: true
5713
+ }),
5714
+ input.timeoutMs
5715
+ );
5716
+ return this.createStepResult(controller.sessionRef, controller.pageRef, startedAt, {
5717
+ frameRef: frame.frameRef,
5718
+ documentRef: frame.currentDocument.documentRef,
5719
+ documentEpoch: frame.currentDocument.documentEpoch,
5720
+ events: this.drainQueuedEvents(controller.pageRef),
5721
+ data: evaluated.result?.value
5722
+ });
5723
+ } catch (error) {
5724
+ throw normalizeAbpError(error, controller.pageRef);
5725
+ }
5726
+ }
5680
5727
  async addInitScript(_input) {
5681
5728
  throw unsupportedCapabilityError("instrumentation.initScripts");
5682
5729
  }
@@ -6932,6 +6979,15 @@ var AbpBrowserCoreEngine = class _AbpBrowserCoreEngine {
6932
6979
  }
6933
6980
  return frame;
6934
6981
  }
6982
+ async ensureFrameExecutionContext(controller, cdpFrameId) {
6983
+ const isolatedWorld = await controller.cdp.send("Page.createIsolatedWorld", {
6984
+ frameId: cdpFrameId,
6985
+ worldName: "__opensteer_snapshot__",
6986
+ // CDP spells this field as `grantUniveralAccess`.
6987
+ grantUniveralAccess: true
6988
+ });
6989
+ return isolatedWorld.executionContextId;
6990
+ }
6935
6991
  requireDocument(documentRef) {
6936
6992
  const document = this.documents.get(documentRef);
6937
6993
  if (!document) {