@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.
@@ -141,7 +141,7 @@ var BROWSER_MOUSE_BUTTON_MASKS = Object.freeze({
141
141
  /** Tool identity embedded in HAR 1.2 documents. */
142
142
  var BROWSER_HAR_CREATOR = Object.freeze({
143
143
  name: "@orkestrel/browser",
144
- version: "0.0.8"
144
+ version: "0.0.11"
145
145
  });
146
146
  /** Attribute used to tag temporary screenshot styles and masks. */
147
147
  var BROWSER_SCREENSHOT_ATTRIBUTE = "data-orkestrel-screenshot";
@@ -4958,9 +4958,9 @@ var BrowserFrame = class {
4958
4958
  this.assert();
4959
4959
  await this.#selectors.css(selector).wait(options);
4960
4960
  }
4961
- async send(method, params) {
4961
+ async send(method, params, timeout) {
4962
4962
  this.assert();
4963
- return await this.#client.send(method, params, await this.#sessionId());
4963
+ return await this.#client.send(method, params, await this.#sessionId(), timeout);
4964
4964
  }
4965
4965
  async subscribe(method, handler) {
4966
4966
  this.assert();
@@ -4975,12 +4975,6 @@ var BrowserFrame = class {
4975
4975
  assert() {
4976
4976
  if (!this.#client.connected) throw new BrowserError("Browser frame is disconnected", void 0, { frame: this.#id });
4977
4977
  }
4978
- async request(method, params, timeout) {
4979
- return await this.#client.send(method, params, await this.#sessionId(), timeout);
4980
- }
4981
- async raw(expression, timeout) {
4982
- return await this.#evaluate(expression, timeout);
4983
- }
4984
4978
  update(url) {
4985
4979
  this.#url = url;
4986
4980
  }
@@ -6199,7 +6193,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6199
6193
  this.assert();
6200
6194
  const params = { ...browserScreenshotToParams(options) };
6201
6195
  if (options?.full === true) {
6202
- const metrics = await this.request("Page.getLayoutMetrics");
6196
+ const metrics = await this.send("Page.getLayoutMetrics");
6203
6197
  const size = (0, _orkestrel_contract.isRecord)(metrics) && (0, _orkestrel_contract.isRecord)(metrics["cssContentSize"]) ? metrics["cssContentSize"] : (0, _orkestrel_contract.isRecord)(metrics) && (0, _orkestrel_contract.isRecord)(metrics["contentSize"]) ? metrics["contentSize"] : void 0;
6204
6198
  const width = size?.["width"];
6205
6199
  const height = size?.["height"];
@@ -6217,7 +6211,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6217
6211
  const ratio = options.scale === "css" ? 1 : await this.evaluate("devicePixelRatio");
6218
6212
  if (!(0, _orkestrel_contract.isFiniteNumber)(ratio) || ratio <= 0) throw new BrowserError("Browser screenshot device scale is malformed");
6219
6213
  if (!(0, _orkestrel_contract.isRecord)(params["clip"])) {
6220
- const metrics = await this.request("Page.getLayoutMetrics");
6214
+ const metrics = await this.send("Page.getLayoutMetrics");
6221
6215
  const viewport = (0, _orkestrel_contract.isRecord)(metrics) && (0, _orkestrel_contract.isRecord)(metrics["cssVisualViewport"]) ? metrics["cssVisualViewport"] : void 0;
6222
6216
  if (viewport === void 0 || !(0, _orkestrel_contract.isFiniteNumber)(viewport["pageX"]) || !(0, _orkestrel_contract.isFiniteNumber)(viewport["pageY"]) || !(0, _orkestrel_contract.isFiniteNumber)(viewport["clientWidth"]) || viewport["clientWidth"] <= 0 || !(0, _orkestrel_contract.isFiniteNumber)(viewport["clientHeight"]) || viewport["clientHeight"] <= 0) throw new BrowserError("Browser screenshot viewport metrics are malformed");
6223
6217
  params["clip"] = {
@@ -6239,7 +6233,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6239
6233
  token = value;
6240
6234
  }
6241
6235
  if (options?.transparent === true) {
6242
- await this.request("Emulation.setDefaultBackgroundColorOverride", { color: {
6236
+ await this.send("Emulation.setDefaultBackgroundColorOverride", { color: {
6243
6237
  r: 0,
6244
6238
  g: 0,
6245
6239
  b: 0,
@@ -6247,7 +6241,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6247
6241
  } });
6248
6242
  transparent = true;
6249
6243
  }
6250
- const result = await this.request("Page.captureScreenshot", params);
6244
+ const result = await this.send("Page.captureScreenshot", params);
6251
6245
  if (!(0, _orkestrel_contract.isRecord)(result) || !(0, _orkestrel_contract.isString)(result["data"])) throw new BrowserError("Screenshot failed: no data returned");
6252
6246
  const bytes = decodeBase64(result["data"]);
6253
6247
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6256,13 +6250,13 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6256
6250
  path: options?.path
6257
6251
  };
6258
6252
  } finally {
6259
- if (transparent) await this.request("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6253
+ if (transparent) await this.send("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6260
6254
  if (token !== void 0) await this.evaluate(compileScreenshotCleanupExpression(token)).catch(() => void 0);
6261
6255
  }
6262
6256
  }
6263
6257
  async pdf(options) {
6264
6258
  this.assert();
6265
- const result = await this.request("Page.printToPDF", browserPDFToParams(options));
6259
+ const result = await this.send("Page.printToPDF", browserPDFToParams(options));
6266
6260
  if (!(0, _orkestrel_contract.isRecord)(result) || !(0, _orkestrel_contract.isString)(result["data"])) throw new BrowserError("PDF failed: no data returned");
6267
6261
  const bytes = decodeBase64(result["data"]);
6268
6262
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6280,12 +6274,12 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6280
6274
  }
6281
6275
  async frames() {
6282
6276
  this.assert();
6283
- return readBrowserFrames(await this.request("Page.getFrameTree")).map((frame) => this.#frame(frame));
6277
+ return readBrowserFrames(await this.send("Page.getFrameTree")).map((frame) => this.#frame(frame));
6284
6278
  }
6285
6279
  async snapshot(options) {
6286
6280
  this.assert();
6287
6281
  const styles = options?.styles ?? [];
6288
- return new BrowserSnapshot(decodeBrowserSnapshot(await this.request("DOMSnapshot.captureSnapshot", {
6282
+ return new BrowserSnapshot(decodeBrowserSnapshot(await this.send("DOMSnapshot.captureSnapshot", {
6289
6283
  computedStyles: [...styles],
6290
6284
  includePaintOrder: options?.paint ?? false,
6291
6285
  includeDOMRects: options?.rects ?? false
@@ -6338,7 +6332,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6338
6332
  wait.catch(() => void 0);
6339
6333
  let loader;
6340
6334
  try {
6341
- const result = await this.request("Page.navigate", { url }, timeout);
6335
+ const result = await this.send("Page.navigate", { url }, timeout);
6342
6336
  if ((0, _orkestrel_contract.isRecord)(result) && (0, _orkestrel_contract.isString)(result["errorText"])) throw new BrowserError(`Navigation failed: ${result["errorText"]}`);
6343
6337
  if ((0, _orkestrel_contract.isRecord)(result) && (0, _orkestrel_contract.isString)(result["loaderId"])) loader = result["loaderId"];
6344
6338
  await wait;
@@ -6357,7 +6351,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6357
6351
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6358
6352
  wait.catch(() => void 0);
6359
6353
  try {
6360
- await this.request("Page.reload", void 0, timeout);
6354
+ await this.send("Page.reload", void 0, timeout);
6361
6355
  await wait;
6362
6356
  } catch (error) {
6363
6357
  this.#clearNavigationWatch(watch);
@@ -6382,7 +6376,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6382
6376
  async #navigateHistory(offset, options) {
6383
6377
  const timeout = options?.timeout ?? 3e4;
6384
6378
  validateBrowserTimeout(timeout);
6385
- const history = await this.request("Page.getNavigationHistory");
6379
+ const history = await this.send("Page.getNavigationHistory");
6386
6380
  if (!(0, _orkestrel_contract.isRecord)(history) || !(0, _orkestrel_contract.isInteger)(history["currentIndex"]) || !(0, _orkestrel_contract.isArray)(history["entries"])) throw new BrowserError("Navigation history is malformed");
6387
6381
  const entry = history["entries"][history["currentIndex"] + offset];
6388
6382
  if (!(0, _orkestrel_contract.isRecord)(entry) || !(0, _orkestrel_contract.isInteger)(entry["id"])) return {
@@ -6394,7 +6388,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6394
6388
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6395
6389
  wait.catch(() => void 0);
6396
6390
  try {
6397
- await this.request("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6391
+ await this.send("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6398
6392
  await wait;
6399
6393
  } catch (error) {
6400
6394
  this.#clearNavigationWatch(watch);
@@ -6424,7 +6418,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6424
6418
  }
6425
6419
  async #completeNavigation(watch, loader) {
6426
6420
  try {
6427
- const resolved = requireBrowserString(await this.raw("location.href"), "Navigation URL");
6421
+ const resolved = requireBrowserString(await this.evaluate("location.href"), "Navigation URL");
6428
6422
  this.update(resolved);
6429
6423
  return this.#navigationResult(watch, resolved, loader);
6430
6424
  } catch (error) {
@@ -6558,7 +6552,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6558
6552
  }
6559
6553
  async #stopLoading(timeout) {
6560
6554
  try {
6561
- await this.request("Page.stopLoading", void 0, timeout);
6555
+ await this.send("Page.stopLoading", void 0, timeout);
6562
6556
  } catch {}
6563
6557
  }
6564
6558
  #handleNavigationResponse(response) {