@orkestrel/browser 0.0.9 → 0.0.11

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.
@@ -6,7 +6,72 @@ let _orkestrel_html = require("@orkestrel/html");
6
6
  /** Base64 alphabet, index-ordered, used to build {@link BASE64_LOOKUP}. */
7
7
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
8
  /** Base64 character to 6-bit value lookup table, derived from {@link BASE64_CHARS}. */
9
- var BASE64_LOOKUP = Object.freeze(Object.fromEntries(BASE64_CHARS.split("").map((char, index) => [char, index])));
9
+ var BASE64_LOOKUP = Object.freeze({
10
+ A: 0,
11
+ B: 1,
12
+ C: 2,
13
+ D: 3,
14
+ E: 4,
15
+ F: 5,
16
+ G: 6,
17
+ H: 7,
18
+ I: 8,
19
+ J: 9,
20
+ K: 10,
21
+ L: 11,
22
+ M: 12,
23
+ N: 13,
24
+ O: 14,
25
+ P: 15,
26
+ Q: 16,
27
+ R: 17,
28
+ S: 18,
29
+ T: 19,
30
+ U: 20,
31
+ V: 21,
32
+ W: 22,
33
+ X: 23,
34
+ Y: 24,
35
+ Z: 25,
36
+ a: 26,
37
+ b: 27,
38
+ c: 28,
39
+ d: 29,
40
+ e: 30,
41
+ f: 31,
42
+ g: 32,
43
+ h: 33,
44
+ i: 34,
45
+ j: 35,
46
+ k: 36,
47
+ l: 37,
48
+ m: 38,
49
+ n: 39,
50
+ o: 40,
51
+ p: 41,
52
+ q: 42,
53
+ r: 43,
54
+ s: 44,
55
+ t: 45,
56
+ u: 46,
57
+ v: 47,
58
+ w: 48,
59
+ x: 49,
60
+ y: 50,
61
+ z: 51,
62
+ "0": 52,
63
+ "1": 53,
64
+ "2": 54,
65
+ "3": 55,
66
+ "4": 56,
67
+ "5": 57,
68
+ "6": 58,
69
+ "7": 59,
70
+ "8": 60,
71
+ "9": 61,
72
+ "+": 62,
73
+ "/": 63
74
+ });
10
75
  /** Default timeout in milliseconds for browser connection, requests, and navigation. */
11
76
  var BROWSER_DEFAULT_TIMEOUT_MS = 3e4;
12
77
  /**
@@ -76,7 +141,7 @@ var BROWSER_MOUSE_BUTTON_MASKS = Object.freeze({
76
141
  /** Tool identity embedded in HAR 1.2 documents. */
77
142
  var BROWSER_HAR_CREATOR = Object.freeze({
78
143
  name: "@orkestrel/browser",
79
- version: "0.0.8"
144
+ version: "0.0.11"
80
145
  });
81
146
  /** Attribute used to tag temporary screenshot styles and masks. */
82
147
  var BROWSER_SCREENSHOT_ATTRIBUTE = "data-orkestrel-screenshot";
@@ -4893,9 +4958,9 @@ var BrowserFrame = class {
4893
4958
  this.assert();
4894
4959
  await this.#selectors.css(selector).wait(options);
4895
4960
  }
4896
- async send(method, params) {
4961
+ async send(method, params, timeout) {
4897
4962
  this.assert();
4898
- return await this.#client.send(method, params, await this.#sessionId());
4963
+ return await this.#client.send(method, params, await this.#sessionId(), timeout);
4899
4964
  }
4900
4965
  async subscribe(method, handler) {
4901
4966
  this.assert();
@@ -4910,12 +4975,6 @@ var BrowserFrame = class {
4910
4975
  assert() {
4911
4976
  if (!this.#client.connected) throw new BrowserError("Browser frame is disconnected", void 0, { frame: this.#id });
4912
4977
  }
4913
- async request(method, params, timeout) {
4914
- return await this.#client.send(method, params, await this.#sessionId(), timeout);
4915
- }
4916
- async raw(expression, timeout) {
4917
- return await this.#evaluate(expression, timeout);
4918
- }
4919
4978
  update(url) {
4920
4979
  this.#url = url;
4921
4980
  }
@@ -6134,7 +6193,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6134
6193
  this.assert();
6135
6194
  const params = { ...browserScreenshotToParams(options) };
6136
6195
  if (options?.full === true) {
6137
- const metrics = await this.request("Page.getLayoutMetrics");
6196
+ const metrics = await this.send("Page.getLayoutMetrics");
6138
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;
6139
6198
  const width = size?.["width"];
6140
6199
  const height = size?.["height"];
@@ -6152,7 +6211,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6152
6211
  const ratio = options.scale === "css" ? 1 : await this.evaluate("devicePixelRatio");
6153
6212
  if (!(0, _orkestrel_contract.isFiniteNumber)(ratio) || ratio <= 0) throw new BrowserError("Browser screenshot device scale is malformed");
6154
6213
  if (!(0, _orkestrel_contract.isRecord)(params["clip"])) {
6155
- const metrics = await this.request("Page.getLayoutMetrics");
6214
+ const metrics = await this.send("Page.getLayoutMetrics");
6156
6215
  const viewport = (0, _orkestrel_contract.isRecord)(metrics) && (0, _orkestrel_contract.isRecord)(metrics["cssVisualViewport"]) ? metrics["cssVisualViewport"] : void 0;
6157
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");
6158
6217
  params["clip"] = {
@@ -6174,7 +6233,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6174
6233
  token = value;
6175
6234
  }
6176
6235
  if (options?.transparent === true) {
6177
- await this.request("Emulation.setDefaultBackgroundColorOverride", { color: {
6236
+ await this.send("Emulation.setDefaultBackgroundColorOverride", { color: {
6178
6237
  r: 0,
6179
6238
  g: 0,
6180
6239
  b: 0,
@@ -6182,7 +6241,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6182
6241
  } });
6183
6242
  transparent = true;
6184
6243
  }
6185
- const result = await this.request("Page.captureScreenshot", params);
6244
+ const result = await this.send("Page.captureScreenshot", params);
6186
6245
  if (!(0, _orkestrel_contract.isRecord)(result) || !(0, _orkestrel_contract.isString)(result["data"])) throw new BrowserError("Screenshot failed: no data returned");
6187
6246
  const bytes = decodeBase64(result["data"]);
6188
6247
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6191,13 +6250,13 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6191
6250
  path: options?.path
6192
6251
  };
6193
6252
  } finally {
6194
- if (transparent) await this.request("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6253
+ if (transparent) await this.send("Emulation.setDefaultBackgroundColorOverride").catch(() => void 0);
6195
6254
  if (token !== void 0) await this.evaluate(compileScreenshotCleanupExpression(token)).catch(() => void 0);
6196
6255
  }
6197
6256
  }
6198
6257
  async pdf(options) {
6199
6258
  this.assert();
6200
- const result = await this.request("Page.printToPDF", browserPDFToParams(options));
6259
+ const result = await this.send("Page.printToPDF", browserPDFToParams(options));
6201
6260
  if (!(0, _orkestrel_contract.isRecord)(result) || !(0, _orkestrel_contract.isString)(result["data"])) throw new BrowserError("PDF failed: no data returned");
6202
6261
  const bytes = decodeBase64(result["data"]);
6203
6262
  if (options?.path !== void 0) await this.save(options.path, bytes);
@@ -6215,12 +6274,12 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6215
6274
  }
6216
6275
  async frames() {
6217
6276
  this.assert();
6218
- 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));
6219
6278
  }
6220
6279
  async snapshot(options) {
6221
6280
  this.assert();
6222
6281
  const styles = options?.styles ?? [];
6223
- return new BrowserSnapshot(decodeBrowserSnapshot(await this.request("DOMSnapshot.captureSnapshot", {
6282
+ return new BrowserSnapshot(decodeBrowserSnapshot(await this.send("DOMSnapshot.captureSnapshot", {
6224
6283
  computedStyles: [...styles],
6225
6284
  includePaintOrder: options?.paint ?? false,
6226
6285
  includeDOMRects: options?.rects ?? false
@@ -6273,7 +6332,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6273
6332
  wait.catch(() => void 0);
6274
6333
  let loader;
6275
6334
  try {
6276
- const result = await this.request("Page.navigate", { url }, timeout);
6335
+ const result = await this.send("Page.navigate", { url }, timeout);
6277
6336
  if ((0, _orkestrel_contract.isRecord)(result) && (0, _orkestrel_contract.isString)(result["errorText"])) throw new BrowserError(`Navigation failed: ${result["errorText"]}`);
6278
6337
  if ((0, _orkestrel_contract.isRecord)(result) && (0, _orkestrel_contract.isString)(result["loaderId"])) loader = result["loaderId"];
6279
6338
  await wait;
@@ -6292,7 +6351,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6292
6351
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6293
6352
  wait.catch(() => void 0);
6294
6353
  try {
6295
- await this.request("Page.reload", void 0, timeout);
6354
+ await this.send("Page.reload", void 0, timeout);
6296
6355
  await wait;
6297
6356
  } catch (error) {
6298
6357
  this.#clearNavigationWatch(watch);
@@ -6317,7 +6376,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6317
6376
  async #navigateHistory(offset, options) {
6318
6377
  const timeout = options?.timeout ?? 3e4;
6319
6378
  validateBrowserTimeout(timeout);
6320
- const history = await this.request("Page.getNavigationHistory");
6379
+ const history = await this.send("Page.getNavigationHistory");
6321
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");
6322
6381
  const entry = history["entries"][history["currentIndex"] + offset];
6323
6382
  if (!(0, _orkestrel_contract.isRecord)(entry) || !(0, _orkestrel_contract.isInteger)(entry["id"])) return {
@@ -6329,7 +6388,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6329
6388
  const wait = this.#waitForLoadEvent(options?.condition ?? "load", timeout);
6330
6389
  wait.catch(() => void 0);
6331
6390
  try {
6332
- await this.request("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6391
+ await this.send("Page.navigateToHistoryEntry", { entryId: entry["id"] }, timeout);
6333
6392
  await wait;
6334
6393
  } catch (error) {
6335
6394
  this.#clearNavigationWatch(watch);
@@ -6359,7 +6418,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6359
6418
  }
6360
6419
  async #completeNavigation(watch, loader) {
6361
6420
  try {
6362
- const resolved = requireBrowserString(await this.raw("location.href"), "Navigation URL");
6421
+ const resolved = requireBrowserString(await this.evaluate("location.href"), "Navigation URL");
6363
6422
  this.update(resolved);
6364
6423
  return this.#navigationResult(watch, resolved, loader);
6365
6424
  } catch (error) {
@@ -6493,7 +6552,7 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6493
6552
  }
6494
6553
  async #stopLoading(timeout) {
6495
6554
  try {
6496
- await this.request("Page.stopLoading", void 0, timeout);
6555
+ await this.send("Page.stopLoading", void 0, timeout);
6497
6556
  } catch {}
6498
6557
  }
6499
6558
  #handleNavigationResponse(response) {