@orkestrel/browser 0.0.10 → 0.0.12

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.
@@ -49,7 +49,7 @@ export declare const BROWSER_FRAME_WORLD_NAME = "__orkestrelBrowserFrame";
49
49
  /** Tool identity embedded in HAR 1.2 documents. */
50
50
  export declare const BROWSER_HAR_CREATOR: Readonly<{
51
51
  name: "@orkestrel/browser";
52
- version: "0.0.8";
52
+ version: "0.0.11";
53
53
  }>;
54
54
 
55
55
  /** CDP Input modifier bit values keyed by canonical key name. */
@@ -739,14 +739,12 @@ export declare class BrowserFrame implements BrowserFrameInterface {
739
739
  evaluate(expression: string, timeout?: number): Promise<unknown>;
740
740
  handle(expression: string): Promise<BrowserHandleInterface>;
741
741
  wait(selector: string, options?: BrowserWaitOptions): Promise<void>;
742
- send(method: string, params?: Readonly<Record<string, unknown>>): Promise<unknown>;
742
+ send(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
743
743
  subscribe(method: string, handler: CDPHandler): Promise<void>;
744
744
  unsubscribe(method: string, handler: CDPHandler): Promise<void>;
745
745
  save(path: string, _bytes: Uint8Array): Promise<void>;
746
- protected assert(): void;
747
- protected request(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
748
- protected raw(expression: string, timeout?: number): Promise<unknown>;
749
- protected update(url: string): void;
746
+ assert(): void;
747
+ update(url: string): void;
750
748
  }
751
749
 
752
750
  /**
@@ -781,7 +779,9 @@ export declare interface BrowserFrameInfo {
781
779
  * - `select` — choose option(s) in a `<select>` element
782
780
  * - `evaluate` — execute a JavaScript expression in the page context
783
781
  * - `wait` — wait for an element state
784
- * - `send` — issue a raw CDP method in the frame's current target session
782
+ * - `send` — issue a raw CDP method in the frame's current target session, with an optional per-call timeout
783
+ * - `assert` — throw when the frame can no longer accept protocol work
784
+ * - `update` — record an externally observed URL as the frame's current URL
785
785
  */
786
786
  export declare interface BrowserFrameInterface {
787
787
  readonly id: string;
@@ -801,10 +801,12 @@ export declare interface BrowserFrameInterface {
801
801
  evaluate(expression: string, timeout?: number): Promise<unknown>;
802
802
  handle(expression: string): Promise<BrowserHandleInterface>;
803
803
  wait(selector: string, options?: BrowserWaitOptions): Promise<void>;
804
- send(method: string, params?: Readonly<Record<string, unknown>>): Promise<unknown>;
804
+ send(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
805
805
  subscribe(method: string, handler: CDPHandler): Promise<void>;
806
806
  unsubscribe(method: string, handler: CDPHandler): Promise<void>;
807
807
  save(path: string, bytes: Uint8Array): Promise<void>;
808
+ assert(): void;
809
+ update(url: string): void;
808
810
  }
809
811
 
810
812
  /** Function coverage inside one script. */
@@ -1348,7 +1350,7 @@ export declare class BrowserPage extends BrowserFrame implements BrowserPageInte
1348
1350
  codegen(options?: BrowserCodegenOptions): Promise<BrowserCodegenInterface>;
1349
1351
  destroy(): Promise<void>;
1350
1352
  close(): Promise<void>;
1351
- protected assert(): void;
1353
+ assert(): void;
1352
1354
  }
1353
1355
 
1354
1356
  /** One uncaught page exception. */
@@ -49,7 +49,7 @@ export declare const BROWSER_FRAME_WORLD_NAME = "__orkestrelBrowserFrame";
49
49
  /** Tool identity embedded in HAR 1.2 documents. */
50
50
  export declare const BROWSER_HAR_CREATOR: Readonly<{
51
51
  name: "@orkestrel/browser";
52
- version: "0.0.8";
52
+ version: "0.0.11";
53
53
  }>;
54
54
 
55
55
  /** CDP Input modifier bit values keyed by canonical key name. */
@@ -739,14 +739,12 @@ export declare class BrowserFrame implements BrowserFrameInterface {
739
739
  evaluate(expression: string, timeout?: number): Promise<unknown>;
740
740
  handle(expression: string): Promise<BrowserHandleInterface>;
741
741
  wait(selector: string, options?: BrowserWaitOptions): Promise<void>;
742
- send(method: string, params?: Readonly<Record<string, unknown>>): Promise<unknown>;
742
+ send(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
743
743
  subscribe(method: string, handler: CDPHandler): Promise<void>;
744
744
  unsubscribe(method: string, handler: CDPHandler): Promise<void>;
745
745
  save(path: string, _bytes: Uint8Array): Promise<void>;
746
- protected assert(): void;
747
- protected request(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
748
- protected raw(expression: string, timeout?: number): Promise<unknown>;
749
- protected update(url: string): void;
746
+ assert(): void;
747
+ update(url: string): void;
750
748
  }
751
749
 
752
750
  /**
@@ -781,7 +779,9 @@ export declare interface BrowserFrameInfo {
781
779
  * - `select` — choose option(s) in a `<select>` element
782
780
  * - `evaluate` — execute a JavaScript expression in the page context
783
781
  * - `wait` — wait for an element state
784
- * - `send` — issue a raw CDP method in the frame's current target session
782
+ * - `send` — issue a raw CDP method in the frame's current target session, with an optional per-call timeout
783
+ * - `assert` — throw when the frame can no longer accept protocol work
784
+ * - `update` — record an externally observed URL as the frame's current URL
785
785
  */
786
786
  export declare interface BrowserFrameInterface {
787
787
  readonly id: string;
@@ -801,10 +801,12 @@ export declare interface BrowserFrameInterface {
801
801
  evaluate(expression: string, timeout?: number): Promise<unknown>;
802
802
  handle(expression: string): Promise<BrowserHandleInterface>;
803
803
  wait(selector: string, options?: BrowserWaitOptions): Promise<void>;
804
- send(method: string, params?: Readonly<Record<string, unknown>>): Promise<unknown>;
804
+ send(method: string, params?: Readonly<Record<string, unknown>>, timeout?: number): Promise<unknown>;
805
805
  subscribe(method: string, handler: CDPHandler): Promise<void>;
806
806
  unsubscribe(method: string, handler: CDPHandler): Promise<void>;
807
807
  save(path: string, bytes: Uint8Array): Promise<void>;
808
+ assert(): void;
809
+ update(url: string): void;
808
810
  }
809
811
 
810
812
  /** Function coverage inside one script. */
@@ -1348,7 +1350,7 @@ export declare class BrowserPage extends BrowserFrame implements BrowserPageInte
1348
1350
  codegen(options?: BrowserCodegenOptions): Promise<BrowserCodegenInterface>;
1349
1351
  destroy(): Promise<void>;
1350
1352
  close(): Promise<void>;
1351
- protected assert(): void;
1353
+ assert(): void;
1352
1354
  }
1353
1355
 
1354
1356
  /** One uncaught page exception. */
@@ -140,7 +140,7 @@ var BROWSER_MOUSE_BUTTON_MASKS = Object.freeze({
140
140
  /** Tool identity embedded in HAR 1.2 documents. */
141
141
  var BROWSER_HAR_CREATOR = Object.freeze({
142
142
  name: "@orkestrel/browser",
143
- version: "0.0.8"
143
+ version: "0.0.11"
144
144
  });
145
145
  /** Attribute used to tag temporary screenshot styles and masks. */
146
146
  var BROWSER_SCREENSHOT_ATTRIBUTE = "data-orkestrel-screenshot";
@@ -4957,9 +4957,9 @@ var BrowserFrame = class {
4957
4957
  this.assert();
4958
4958
  await this.#selectors.css(selector).wait(options);
4959
4959
  }
4960
- async send(method, params) {
4960
+ async send(method, params, timeout) {
4961
4961
  this.assert();
4962
- return await this.#client.send(method, params, await this.#sessionId());
4962
+ return await this.#client.send(method, params, await this.#sessionId(), timeout);
4963
4963
  }
4964
4964
  async subscribe(method, handler) {
4965
4965
  this.assert();
@@ -4974,12 +4974,6 @@ var BrowserFrame = class {
4974
4974
  assert() {
4975
4975
  if (!this.#client.connected) throw new BrowserError("Browser frame is disconnected", void 0, { frame: this.#id });
4976
4976
  }
4977
- async request(method, params, timeout) {
4978
- return await this.#client.send(method, params, await this.#sessionId(), timeout);
4979
- }
4980
- async raw(expression, timeout) {
4981
- return await this.#evaluate(expression, timeout);
4982
- }
4983
4977
  update(url) {
4984
4978
  this.#url = url;
4985
4979
  }
@@ -6198,7 +6192,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6198
6192
  this.assert();
6199
6193
  const params = { ...browserScreenshotToParams(options) };
6200
6194
  if (options?.full === true) {
6201
- const metrics = await this.request("Page.getLayoutMetrics");
6195
+ const metrics = await this.send("Page.getLayoutMetrics");
6202
6196
  const size = isRecord(metrics) && isRecord(metrics["cssContentSize"]) ? metrics["cssContentSize"] : isRecord(metrics) && isRecord(metrics["contentSize"]) ? metrics["contentSize"] : void 0;
6203
6197
  const width = size?.["width"];
6204
6198
  const height = size?.["height"];
@@ -6216,7 +6210,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6216
6210
  const ratio = options.scale === "css" ? 1 : await this.evaluate("devicePixelRatio");
6217
6211
  if (!isFiniteNumber(ratio) || ratio <= 0) throw new BrowserError("Browser screenshot device scale is malformed");
6218
6212
  if (!isRecord(params["clip"])) {
6219
- const metrics = await this.request("Page.getLayoutMetrics");
6213
+ const metrics = await this.send("Page.getLayoutMetrics");
6220
6214
  const viewport = isRecord(metrics) && isRecord(metrics["cssVisualViewport"]) ? metrics["cssVisualViewport"] : void 0;
6221
6215
  if (viewport === void 0 || !isFiniteNumber(viewport["pageX"]) || !isFiniteNumber(viewport["pageY"]) || !isFiniteNumber(viewport["clientWidth"]) || viewport["clientWidth"] <= 0 || !isFiniteNumber(viewport["clientHeight"]) || viewport["clientHeight"] <= 0) throw new BrowserError("Browser screenshot viewport metrics are malformed");
6222
6216
  params["clip"] = {
@@ -6238,7 +6232,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6238
6232
  token = value;
6239
6233
  }
6240
6234
  if (options?.transparent === true) {
6241
- await this.request("Emulation.setDefaultBackgroundColorOverride", { color: {
6235
+ await this.send("Emulation.setDefaultBackgroundColorOverride", { color: {
6242
6236
  r: 0,
6243
6237
  g: 0,
6244
6238
  b: 0,
@@ -6246,7 +6240,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6246
6240
  } });
6247
6241
  transparent = true;
6248
6242
  }
6249
- const result = await this.request("Page.captureScreenshot", params);
6243
+ const result = await this.send("Page.captureScreenshot", params);
6250
6244
  if (!isRecord(result) || !isString(result["data"])) throw new BrowserError("Screenshot failed: no data returned");
6251
6245
  const bytes = decodeBase64(result["data"]);
6252
6246
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6255,13 +6249,13 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6255
6249
  path: options?.path
6256
6250
  };
6257
6251
  } finally {
6258
- if (transparent) await this.request("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6252
+ if (transparent) await this.send("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6259
6253
  if (token !== void 0) await this.evaluate(compileScreenshotCleanupExpression(token)).catch(() => void 0);
6260
6254
  }
6261
6255
  }
6262
6256
  async pdf(options) {
6263
6257
  this.assert();
6264
- const result = await this.request("Page.printToPDF", browserPDFToParams(options));
6258
+ const result = await this.send("Page.printToPDF", browserPDFToParams(options));
6265
6259
  if (!isRecord(result) || !isString(result["data"])) throw new BrowserError("PDF failed: no data returned");
6266
6260
  const bytes = decodeBase64(result["data"]);
6267
6261
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6279,12 +6273,12 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6279
6273
  }
6280
6274
  async frames() {
6281
6275
  this.assert();
6282
- return readBrowserFrames(await this.request("Page.getFrameTree")).map((frame) => this.#frame(frame));
6276
+ return readBrowserFrames(await this.send("Page.getFrameTree")).map((frame) => this.#frame(frame));
6283
6277
  }
6284
6278
  async snapshot(options) {
6285
6279
  this.assert();
6286
6280
  const styles = options?.styles ?? [];
6287
- return new BrowserSnapshot(decodeBrowserSnapshot(await this.request("DOMSnapshot.captureSnapshot", {
6281
+ return new BrowserSnapshot(decodeBrowserSnapshot(await this.send("DOMSnapshot.captureSnapshot", {
6288
6282
  computedStyles: [...styles],
6289
6283
  includePaintOrder: options?.paint ?? false,
6290
6284
  includeDOMRects: options?.rects ?? false
@@ -6337,7 +6331,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6337
6331
  wait.catch(() => void 0);
6338
6332
  let loader;
6339
6333
  try {
6340
- const result = await this.request("Page.navigate", { url }, timeout);
6334
+ const result = await this.send("Page.navigate", { url }, timeout);
6341
6335
  if (isRecord(result) && isString(result["errorText"])) throw new BrowserError(`Navigation failed: ${result["errorText"]}`);
6342
6336
  if (isRecord(result) && isString(result["loaderId"])) loader = result["loaderId"];
6343
6337
  await wait;
@@ -6356,7 +6350,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6356
6350
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6357
6351
  wait.catch(() => void 0);
6358
6352
  try {
6359
- await this.request("Page.reload", void 0, timeout);
6353
+ await this.send("Page.reload", void 0, timeout);
6360
6354
  await wait;
6361
6355
  } catch (error) {
6362
6356
  this.#clearNavigationWatch(watch);
@@ -6381,7 +6375,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6381
6375
  async #navigateHistory(offset, options) {
6382
6376
  const timeout = options?.timeout ?? 3e4;
6383
6377
  validateBrowserTimeout(timeout);
6384
- const history = await this.request("Page.getNavigationHistory");
6378
+ const history = await this.send("Page.getNavigationHistory");
6385
6379
  if (!isRecord(history) || !isInteger(history["currentIndex"]) || !isArray(history["entries"])) throw new BrowserError("Navigation history is malformed");
6386
6380
  const entry = history["entries"][history["currentIndex"] + offset];
6387
6381
  if (!isRecord(entry) || !isInteger(entry["id"])) return {
@@ -6393,7 +6387,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6393
6387
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6394
6388
  wait.catch(() => void 0);
6395
6389
  try {
6396
- await this.request("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6390
+ await this.send("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6397
6391
  await wait;
6398
6392
  } catch (error) {
6399
6393
  this.#clearNavigationWatch(watch);
@@ -6423,7 +6417,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6423
6417
  }
6424
6418
  async #completeNavigation(watch, loader) {
6425
6419
  try {
6426
- const resolved = requireBrowserString(await this.raw("location.href"), "Navigation URL");
6420
+ const resolved = requireBrowserString(await this.evaluate("location.href"), "Navigation URL");
6427
6421
  this.update(resolved);
6428
6422
  return this.#navigationResult(watch, resolved, loader);
6429
6423
  } catch (error) {
@@ -6557,7 +6551,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6557
6551
  }
6558
6552
  async #stopLoading(timeout) {
6559
6553
  try {
6560
- await this.request("Page.stopLoading", void 0, timeout);
6554
+ await this.send("Page.stopLoading", void 0, timeout);
6561
6555
  } catch {}
6562
6556
  }
6563
6557
  #handleNavigationResponse(response) {