@orkestrel/browser 0.0.6 → 0.0.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.
@@ -558,10 +558,10 @@ function createBrowserHAREntry(pending, duration, body, error) {
558
558
  cookies: [],
559
559
  headers: requestHeaders,
560
560
  queryString: query,
561
- postData: post === void 0 ? void 0 : {
561
+ ...post !== void 0 ? { postData: {
562
562
  mimeType: requestMime,
563
563
  text: post
564
- },
564
+ } } : {},
565
565
  headersSize: -1,
566
566
  bodySize: post === void 0 ? 0 : textToBytes(post).byteLength
567
567
  },
@@ -574,8 +574,10 @@ function createBrowserHAREntry(pending, duration, body, error) {
574
574
  content: {
575
575
  size,
576
576
  mimeType: response?.mime ?? "application/octet-stream",
577
- text,
578
- encoding: text === void 0 ? void 0 : "base64"
577
+ ...text !== void 0 ? {
578
+ text,
579
+ encoding: "base64"
580
+ } : {}
579
581
  },
580
582
  redirectURL: redirect,
581
583
  headersSize: -1,
@@ -1387,7 +1389,7 @@ function readBrowserCookiePartition(value) {
1387
1389
  if (!isRecord(value) || !isString(value["topLevelSite"])) return void 0;
1388
1390
  return {
1389
1391
  site: value["topLevelSite"],
1390
- ancestor: isBoolean(value["hasCrossSiteAncestor"]) ? value["hasCrossSiteAncestor"] : void 0
1392
+ ...isBoolean(value["hasCrossSiteAncestor"]) ? { ancestor: value["hasCrossSiteAncestor"] } : {}
1391
1393
  };
1392
1394
  }
1393
1395
  /**
@@ -1609,7 +1611,7 @@ function readBrowserDownloadProgress(value) {
1609
1611
  status,
1610
1612
  received: value["receivedBytes"],
1611
1613
  total: value["totalBytes"],
1612
- path: isString(value["filePath"]) ? value["filePath"] : void 0
1614
+ ...isString(value["filePath"]) ? { path: value["filePath"] } : {}
1613
1615
  }];
1614
1616
  }
1615
1617
  /**
@@ -3509,7 +3511,7 @@ var BrowserClock = class {
3509
3511
  #installed = false;
3510
3512
  #advancing = false;
3511
3513
  #budgetResolve;
3512
- #budgetHandler = () => this.#budgetResolve?.();
3514
+ #budgetHandler = this.#handleBudget.bind(this);
3513
3515
  constructor(frame) {
3514
3516
  this.#frame = frame;
3515
3517
  }
@@ -3609,6 +3611,9 @@ var BrowserClock = class {
3609
3611
  #idle() {
3610
3612
  if (this.#advancing) throw new BrowserError("Browser clock advance is already active");
3611
3613
  }
3614
+ #handleBudget() {
3615
+ this.#budgetResolve?.();
3616
+ }
3612
3617
  };
3613
3618
  //#endregion
3614
3619
  //#region src/core/BrowserCoverage.ts
@@ -3806,8 +3811,8 @@ var BrowserCookieManager = class {
3806
3811
  expires: cookie.expires,
3807
3812
  http: cookie.http,
3808
3813
  secure: cookie.secure,
3809
- site: cookie.site,
3810
- partition: cookie.partition
3814
+ ...cookie.site !== void 0 ? { site: cookie.site } : {},
3815
+ ...cookie.partition !== void 0 ? { partition: cookie.partition } : {}
3811
3816
  })) };
3812
3817
  if (this.#context !== void 0) restore["browserContextId"] = this.#context;
3813
3818
  const result = await this.#client.send("Storage.setCookies", restore);
@@ -3951,12 +3956,14 @@ var BrowserCodegen = class {
3951
3956
  #stopping;
3952
3957
  #shutdown;
3953
3958
  #emitter;
3959
+ #onBindingCalled = this.#handleBindingCalled.bind(this);
3960
+ #onFrameNavigated = this.#handleFrameNavigated.bind(this);
3954
3961
  constructor(client, sessionId, options) {
3955
3962
  this.#client = client;
3956
3963
  this.#sessionId = sessionId;
3957
3964
  this.#emitter = new Emitter({
3958
- on: options?.on,
3959
- error: options?.error
3965
+ ...options?.on !== void 0 ? { on: options.on } : {},
3966
+ ...options?.error !== void 0 ? { error: options.error } : {}
3960
3967
  });
3961
3968
  }
3962
3969
  get emitter() {
@@ -4051,19 +4058,19 @@ var BrowserCodegen = class {
4051
4058
  this.#actions = [];
4052
4059
  this.#emitter.destroy();
4053
4060
  }
4054
- #onBindingCalled = (params) => {
4061
+ #handleBindingCalled(params) {
4055
4062
  if (params["name"] !== "__orkestrelBrowserCodegen") return;
4056
4063
  const action = parseCodegenActionPayload(params["payload"]);
4057
4064
  if (action === void 0) return;
4058
4065
  this.#actions.push(action);
4059
4066
  this.#emitter.emit("action", action);
4060
- };
4061
- #onFrameNavigated = (params) => {
4067
+ }
4068
+ #handleFrameNavigated(params) {
4062
4069
  const action = readCodegenNavigateAction(params);
4063
4070
  if (action === void 0) return;
4064
4071
  this.#actions.push(action);
4065
4072
  this.#emitter.emit("action", action);
4066
- };
4073
+ }
4067
4074
  #unsubscribe() {
4068
4075
  this.#client.unsubscribe("Runtime.bindingCalled", this.#onBindingCalled, this.#sessionId);
4069
4076
  this.#client.unsubscribe("Page.frameNavigated", this.#onFrameNavigated, this.#sessionId);
@@ -4133,12 +4140,7 @@ var BrowserTracing = class {
4133
4140
  #active = false;
4134
4141
  #options;
4135
4142
  #completion;
4136
- #completeHandler = (params) => {
4137
- const completion = this.#completion;
4138
- if (completion === void 0) return;
4139
- if (isString(params["stream"])) completion.resolve(params["stream"]);
4140
- else completion.reject(new BrowserError("Browser trace did not return an IO stream"));
4141
- };
4143
+ #completeHandler = this.#handleComplete.bind(this);
4142
4144
  constructor(frame, writer) {
4143
4145
  this.#frame = frame;
4144
4146
  this.#writer = writer;
@@ -4214,6 +4216,12 @@ var BrowserTracing = class {
4214
4216
  clearTimeout(timer);
4215
4217
  }
4216
4218
  }
4219
+ #handleComplete(params) {
4220
+ const completion = this.#completion;
4221
+ if (completion === void 0) return;
4222
+ if (isString(params["stream"])) completion.resolve(params["stream"]);
4223
+ else completion.reject(new BrowserError("Browser trace did not return an IO stream"));
4224
+ }
4217
4225
  };
4218
4226
  //#endregion
4219
4227
  //#region src/core/BrowserDiagnostics.ts
@@ -4931,8 +4939,8 @@ var BrowserLocator = class BrowserLocator {
4931
4939
  let targetHandle;
4932
4940
  try {
4933
4941
  await target.wait({
4934
- timeout: options?.timeout,
4935
- strict: options?.strict,
4942
+ ...options?.timeout !== void 0 ? { timeout: options.timeout } : {},
4943
+ ...options?.strict !== void 0 ? { strict: options.strict } : {},
4936
4944
  state: "visible"
4937
4945
  });
4938
4946
  targetHandle = await target.frame.handle(compileLocatorExpression(target.query));
@@ -4955,8 +4963,8 @@ var BrowserLocator = class BrowserLocator {
4955
4963
  async #resolve(options, state) {
4956
4964
  validateBrowserActionOptions(options);
4957
4965
  await this.wait({
4958
- timeout: options?.timeout,
4959
- strict: options?.strict,
4966
+ ...options?.timeout !== void 0 ? { timeout: options.timeout } : {},
4967
+ ...options?.strict !== void 0 ? { strict: options.strict } : {},
4960
4968
  state
4961
4969
  });
4962
4970
  return await this.#frame.handle(compileLocatorExpression(this.#query));
@@ -4964,7 +4972,7 @@ var BrowserLocator = class BrowserLocator {
4964
4972
  async #point(handle, options, actionability) {
4965
4973
  if (options?.force !== true) await handle.call(compileActionabilityFunction({
4966
4974
  ...actionability,
4967
- position: options?.position
4975
+ ...options?.position !== void 0 ? { position: options.position } : {}
4968
4976
  }));
4969
4977
  const quad = await this.#quad(handle);
4970
4978
  if (options?.position === void 0) return quad.center;
@@ -5038,29 +5046,29 @@ var BrowserSelectorManager = class {
5038
5046
  return new BrowserLocator(this.#frame, {
5039
5047
  selector: "role",
5040
5048
  value,
5041
- name: options?.name,
5042
- exact: options?.exact
5049
+ ...options?.name !== void 0 ? { name: options.name } : {},
5050
+ ...options?.exact !== void 0 ? { exact: options.exact } : {}
5043
5051
  });
5044
5052
  }
5045
5053
  text(value, options) {
5046
5054
  return new BrowserLocator(this.#frame, {
5047
5055
  selector: "text",
5048
5056
  value,
5049
- exact: options?.exact
5057
+ ...options?.exact !== void 0 ? { exact: options.exact } : {}
5050
5058
  });
5051
5059
  }
5052
5060
  label(value, options) {
5053
5061
  return new BrowserLocator(this.#frame, {
5054
5062
  selector: "label",
5055
5063
  value,
5056
- exact: options?.exact
5064
+ ...options?.exact !== void 0 ? { exact: options.exact } : {}
5057
5065
  });
5058
5066
  }
5059
5067
  placeholder(value, options) {
5060
5068
  return new BrowserLocator(this.#frame, {
5061
5069
  selector: "placeholder",
5062
5070
  value,
5063
- exact: options?.exact
5071
+ ...options?.exact !== void 0 ? { exact: options.exact } : {}
5064
5072
  });
5065
5073
  }
5066
5074
  test(value) {
@@ -5330,45 +5338,11 @@ var BrowserHARManager = class {
5330
5338
  #failure;
5331
5339
  #archive;
5332
5340
  #fallback = false;
5333
- #requestHandler = (request) => {
5334
- if (!this.#recording) return;
5335
- this.#pending.set(request.id, {
5336
- request,
5337
- started: request.walltime === void 0 ? Date.now() : request.walltime * 1e3,
5338
- response: void 0
5339
- });
5340
- };
5341
- #responseHandler = (response) => {
5342
- const pending = this.#pending.get(response.id);
5343
- if (pending === void 0) return;
5344
- this.#pending.set(response.id, {
5345
- request: pending.request,
5346
- started: pending.started,
5347
- response
5348
- });
5349
- };
5350
- #failureHandler = (failure) => {
5351
- const pending = this.#pending.get(failure.id);
5352
- if (pending === void 0) return;
5353
- this.#pending.delete(failure.id);
5354
- this.#entries.push(createBrowserHAREntry(pending, Math.max(0, Date.now() - pending.started), void 0, failure.error));
5355
- };
5356
- #finishHandler = (id) => this.#track(this.#complete(id));
5357
- #replayHandler = async (route) => {
5358
- const entry = this.#archive?.log.entries.find((candidate) => candidate.request.url === route.request.url && candidate.request.method === route.request.method);
5359
- if (entry === void 0 || entry.response.status === 0) {
5360
- if (this.#fallback) await route.continue();
5361
- else await route.abort("Failed");
5362
- return;
5363
- }
5364
- const body = entry.response.content.text === void 0 ? void 0 : entry.response.content.encoding === "base64" ? decodeBase64(entry.response.content.text) : entry.response.content.text;
5365
- await route.fulfill({
5366
- status: entry.response.status,
5367
- phrase: entry.response.statusText,
5368
- headers: browserHARHeadersToRecord(entry.response.headers),
5369
- body
5370
- });
5371
- };
5341
+ #requestHandler = this.#handleRequest.bind(this);
5342
+ #responseHandler = this.#handleResponse.bind(this);
5343
+ #failureHandler = this.#handleFailure.bind(this);
5344
+ #finishHandler = this.#handleFinish.bind(this);
5345
+ #replayHandler = this.#handleReplay.bind(this);
5372
5346
  constructor(network, writer) {
5373
5347
  this.#network = network;
5374
5348
  this.#writer = writer;
@@ -5447,6 +5421,47 @@ var BrowserHARManager = class {
5447
5421
  this.#entries.length = 0;
5448
5422
  this.#pending.clear();
5449
5423
  }
5424
+ #handleRequest(request) {
5425
+ if (!this.#recording) return;
5426
+ this.#pending.set(request.id, {
5427
+ request,
5428
+ started: request.walltime === void 0 ? Date.now() : request.walltime * 1e3,
5429
+ response: void 0
5430
+ });
5431
+ }
5432
+ #handleResponse(response) {
5433
+ const pending = this.#pending.get(response.id);
5434
+ if (pending === void 0) return;
5435
+ this.#pending.set(response.id, {
5436
+ request: pending.request,
5437
+ started: pending.started,
5438
+ response
5439
+ });
5440
+ }
5441
+ #handleFailure(failure) {
5442
+ const pending = this.#pending.get(failure.id);
5443
+ if (pending === void 0) return;
5444
+ this.#pending.delete(failure.id);
5445
+ this.#entries.push(createBrowserHAREntry(pending, Math.max(0, Date.now() - pending.started), void 0, failure.error));
5446
+ }
5447
+ #handleFinish(id) {
5448
+ this.#track(this.#complete(id));
5449
+ }
5450
+ async #handleReplay(route) {
5451
+ const entry = this.#archive?.log.entries.find((candidate) => candidate.request.url === route.request.url && candidate.request.method === route.request.method);
5452
+ if (entry === void 0 || entry.response.status === 0) {
5453
+ if (this.#fallback) await route.continue();
5454
+ else await route.abort("Failed");
5455
+ return;
5456
+ }
5457
+ const body = entry.response.content.text === void 0 ? void 0 : entry.response.content.encoding === "base64" ? decodeBase64(entry.response.content.text) : entry.response.content.text;
5458
+ await route.fulfill({
5459
+ status: entry.response.status,
5460
+ phrase: entry.response.statusText,
5461
+ headers: browserHARHeadersToRecord(entry.response.headers),
5462
+ ...body !== void 0 ? { body } : {}
5463
+ });
5464
+ }
5450
5465
  async #complete(id) {
5451
5466
  const pending = this.#pending.get(id);
5452
5467
  if (pending === void 0) return;
@@ -5596,54 +5611,17 @@ var BrowserNetworkManager = class {
5596
5611
  #fetch = false;
5597
5612
  #destroyed = false;
5598
5613
  #starting;
5599
- #requestHandler = (params) => {
5600
- const request = readBrowserRequest(params);
5601
- if (request !== void 0) this.#emitter.emit("request", request);
5602
- };
5603
- #responseHandler = (params) => {
5604
- const response = readBrowserResponse(params);
5605
- if (response !== void 0) this.#emitter.emit("response", response);
5606
- };
5607
- #failureHandler = (params) => {
5608
- const failure = readBrowserRequestFailure(params);
5609
- if (failure !== void 0) this.#emitter.emit("failure", failure);
5610
- };
5611
- #finishHandler = (params) => {
5612
- if (isString(params["requestId"])) this.#emitter.emit("finish", params["requestId"]);
5613
- };
5614
- #pausedHandler = (params) => {
5615
- this.#route(params).catch(() => void 0);
5616
- };
5617
- #authHandler = (params) => {
5618
- this.#authenticate(params).catch(() => void 0);
5619
- };
5620
- #socketHandler = (params) => {
5621
- if (!isString(params["requestId"]) || !isString(params["url"])) return;
5622
- const socket = new BrowserWebSocket(params["requestId"], params["url"]);
5623
- this.#sockets.set(socket.id, socket);
5624
- this.#emitter.emit("socket", socket);
5625
- };
5626
- #socketReceiveHandler = (params) => {
5627
- const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5628
- const frame = readBrowserWebSocketFrame(params);
5629
- if (socket !== void 0 && frame !== void 0) socket.receive(frame);
5630
- };
5631
- #socketTransmitHandler = (params) => {
5632
- const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5633
- const frame = readBrowserWebSocketFrame(params);
5634
- if (socket !== void 0 && frame !== void 0) socket.transmit(frame);
5635
- };
5636
- #socketErrorHandler = (params) => {
5637
- const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5638
- if (socket !== void 0 && isString(params["errorMessage"])) socket.fail(params["errorMessage"]);
5639
- };
5640
- #socketCloseHandler = (params) => {
5641
- if (!isString(params["requestId"])) return;
5642
- const socket = this.#sockets.get(params["requestId"]);
5643
- if (socket === void 0) return;
5644
- this.#sockets.delete(params["requestId"]);
5645
- socket.close(isFiniteNumber(params["timestamp"]) ? params["timestamp"] : Date.now() / 1e3);
5646
- };
5614
+ #requestHandler = this.#handleRequest.bind(this);
5615
+ #responseHandler = this.#handleResponse.bind(this);
5616
+ #failureHandler = this.#handleFailure.bind(this);
5617
+ #finishHandler = this.#handleFinish.bind(this);
5618
+ #pausedHandler = this.#handlePause.bind(this);
5619
+ #authHandler = this.#handleAuth.bind(this);
5620
+ #socketHandler = this.#handleSocket.bind(this);
5621
+ #socketReceiveHandler = this.#handleSocketReceive.bind(this);
5622
+ #socketTransmitHandler = this.#handleSocketTransmit.bind(this);
5623
+ #socketErrorHandler = this.#handleSocketError.bind(this);
5624
+ #socketCloseHandler = this.#handleSocketClose.bind(this);
5647
5625
  constructor(frame, writer) {
5648
5626
  this.#frame = frame;
5649
5627
  this.#emitter = new Emitter();
@@ -5773,6 +5751,54 @@ var BrowserNetworkManager = class {
5773
5751
  this.#emitter.destroy();
5774
5752
  if (failed) throw failure;
5775
5753
  }
5754
+ #handleRequest(params) {
5755
+ const request = readBrowserRequest(params);
5756
+ if (request !== void 0) this.#emitter.emit("request", request);
5757
+ }
5758
+ #handleResponse(params) {
5759
+ const response = readBrowserResponse(params);
5760
+ if (response !== void 0) this.#emitter.emit("response", response);
5761
+ }
5762
+ #handleFailure(params) {
5763
+ const failure = readBrowserRequestFailure(params);
5764
+ if (failure !== void 0) this.#emitter.emit("failure", failure);
5765
+ }
5766
+ #handleFinish(params) {
5767
+ if (isString(params["requestId"])) this.#emitter.emit("finish", params["requestId"]);
5768
+ }
5769
+ #handlePause(params) {
5770
+ this.#route(params).catch(() => void 0);
5771
+ }
5772
+ #handleAuth(params) {
5773
+ this.#authenticate(params).catch(() => void 0);
5774
+ }
5775
+ #handleSocket(params) {
5776
+ if (!isString(params["requestId"]) || !isString(params["url"])) return;
5777
+ const socket = new BrowserWebSocket(params["requestId"], params["url"]);
5778
+ this.#sockets.set(socket.id, socket);
5779
+ this.#emitter.emit("socket", socket);
5780
+ }
5781
+ #handleSocketReceive(params) {
5782
+ const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5783
+ const frame = readBrowserWebSocketFrame(params);
5784
+ if (socket !== void 0 && frame !== void 0) socket.receive(frame);
5785
+ }
5786
+ #handleSocketTransmit(params) {
5787
+ const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5788
+ const frame = readBrowserWebSocketFrame(params);
5789
+ if (socket !== void 0 && frame !== void 0) socket.transmit(frame);
5790
+ }
5791
+ #handleSocketError(params) {
5792
+ const socket = isString(params["requestId"]) ? this.#sockets.get(params["requestId"]) : void 0;
5793
+ if (socket !== void 0 && isString(params["errorMessage"])) socket.fail(params["errorMessage"]);
5794
+ }
5795
+ #handleSocketClose(params) {
5796
+ if (!isString(params["requestId"])) return;
5797
+ const socket = this.#sockets.get(params["requestId"]);
5798
+ if (socket === void 0) return;
5799
+ this.#sockets.delete(params["requestId"]);
5800
+ socket.close(isFiniteNumber(params["timestamp"]) ? params["timestamp"] : Date.now() / 1e3);
5801
+ }
5776
5802
  async #begin() {
5777
5803
  try {
5778
5804
  await this.#subscribe();
@@ -5876,21 +5902,8 @@ var BrowserNetworkManager = class {
5876
5902
  var BrowserNavigationManager = class {
5877
5903
  #page;
5878
5904
  #waits = /* @__PURE__ */ new Map();
5879
- #navigateHandler = (url) => {
5880
- for (const [id, wait] of this.#waits) {
5881
- if (!matchesBrowserURL(url, wait.pattern)) continue;
5882
- clearTimeout(wait.timer);
5883
- this.#waits.delete(id);
5884
- wait.resolve(url);
5885
- }
5886
- };
5887
- #closeHandler = () => {
5888
- for (const [id, wait] of this.#waits) {
5889
- clearTimeout(wait.timer);
5890
- this.#waits.delete(id);
5891
- wait.reject(new BrowserError("Browser URL wait ended because the page closed"));
5892
- }
5893
- };
5905
+ #navigateHandler = this.#handleNavigate.bind(this);
5906
+ #closeHandler = this.#handleClose.bind(this);
5894
5907
  constructor(page) {
5895
5908
  this.#page = page;
5896
5909
  this.#page.emitter.on("navigate", this.#navigateHandler);
@@ -5925,6 +5938,21 @@ var BrowserNavigationManager = class {
5925
5938
  timeout
5926
5939
  });
5927
5940
  }
5941
+ #handleNavigate(url) {
5942
+ for (const [id, wait] of this.#waits) {
5943
+ if (!matchesBrowserURL(url, wait.pattern)) continue;
5944
+ clearTimeout(wait.timer);
5945
+ this.#waits.delete(id);
5946
+ wait.resolve(url);
5947
+ }
5948
+ }
5949
+ #handleClose() {
5950
+ for (const [id, wait] of this.#waits) {
5951
+ clearTimeout(wait.timer);
5952
+ this.#waits.delete(id);
5953
+ wait.reject(new BrowserError("Browser URL wait ended because the page closed"));
5954
+ }
5955
+ }
5928
5956
  #timeout(options) {
5929
5957
  const timeout = options?.timeout ?? 3e4;
5930
5958
  validateBrowserTimeout(timeout);
@@ -5942,9 +5970,7 @@ var BrowserScriptManager = class {
5942
5970
  #scripts = /* @__PURE__ */ new Map();
5943
5971
  #subscribed = false;
5944
5972
  #destroyed = false;
5945
- #bindingHandler = (params) => {
5946
- this.#call(params).catch(() => void 0);
5947
- };
5973
+ #bindingHandler = this.#handleBinding.bind(this);
5948
5974
  constructor(frame) {
5949
5975
  this.#frame = frame;
5950
5976
  }
@@ -6040,6 +6066,9 @@ var BrowserScriptManager = class {
6040
6066
  });
6041
6067
  }
6042
6068
  }
6069
+ #handleBinding(params) {
6070
+ this.#call(params).catch(() => void 0);
6071
+ }
6043
6072
  #assert() {
6044
6073
  if (this.#destroyed) throw new BrowserError("Browser script manager is destroyed");
6045
6074
  }
@@ -6135,129 +6164,21 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6135
6164
  #loadResolve;
6136
6165
  #loadReject;
6137
6166
  #responses;
6138
- #navigationResponseHandler = (response) => {
6139
- if (response.frame === this.id) this.#responses?.push(response);
6140
- };
6141
- #destroyHandler = (params) => {
6142
- if (!isString(params["targetId"]) || params["targetId"] !== this.#targetId) return;
6143
- this.#closed = true;
6144
- this.#release().catch(() => void 0);
6145
- };
6146
- #loadHandler = (params) => {
6147
- if (this.#loadEvents.includes("Page.navigatedWithinDocument")) {
6148
- const frame = params["frameId"];
6149
- if (isString(frame) && frame === this.id) {
6150
- this.#sameDocument = true;
6151
- this.#resolveLoad();
6152
- return;
6153
- }
6154
- }
6155
- if (this.#loadEvents.includes("Page.frameNavigated")) {
6156
- const frame = params["frame"];
6157
- if (isRecord(frame) && frame["id"] === this.id) this.#resolveLoad();
6158
- return;
6159
- }
6160
- if (this.#loadEvents.includes("Page.loadEventFired") || this.#loadEvents.includes("Page.domContentEventFired")) this.#resolveLoad();
6161
- };
6162
- #frameAttachedHandler = (params) => {
6163
- const frame = params["frameId"];
6164
- const parent = params["parentFrameId"];
6165
- if (!isString(frame)) return;
6166
- this.#emitter.emit("attach", new BrowserFrame(this.#client, (id) => this.#resolveFrameSession(id), frame, "about:blank", isString(parent) ? parent : void 0));
6167
- };
6168
- #frameNavigatedHandler = (params) => {
6169
- const frame = params["frame"];
6170
- if (!isRecord(frame) || !isString(frame["id"]) || !isString(frame["url"])) return;
6171
- if (frame["id"] === this.id) {
6172
- this.update(frame["url"]);
6173
- this.#emitter.emit("navigate", frame["url"]);
6174
- }
6175
- };
6176
- #frameDetachedHandler = (params) => {
6177
- const frame = params["frameId"];
6178
- if (!isString(frame)) return;
6179
- this.#frameSessions.delete(frame);
6180
- this.#emitter.emit("detach", frame);
6181
- };
6182
- #dialogHandler = (params) => {
6183
- const category = params["type"];
6184
- if (category !== "alert" && category !== "confirm" && category !== "prompt" && category !== "beforeunload" || !isString(params["message"])) return;
6185
- this.#emitter.emit("dialog", new BrowserDialog(this, category, params["message"], isString(params["defaultPrompt"]) ? params["defaultPrompt"] : ""));
6186
- };
6187
- #chooserHandler = (params) => {
6188
- const backend = params["backendNodeId"];
6189
- const mode = params["mode"];
6190
- if (!isInteger(backend)) return;
6191
- this.#emitter.emit("chooser", new BrowserFileChooser(this, backend, mode === "selectMultiple"));
6192
- };
6193
- #consoleHandler = (params) => {
6194
- const message = readBrowserConsoleMessage(params);
6195
- if (message !== void 0) this.#emitter.emit("console", message);
6196
- };
6197
- #errorHandler = (params) => {
6198
- const error = readBrowserPageError(params);
6199
- if (error !== void 0) this.#emitter.emit("error", error);
6200
- };
6201
- #crashHandler = () => this.#emitter.emit("crash");
6202
- #downloadHandler = (params) => {
6203
- const start = readBrowserDownloadStart(params);
6204
- if (start === void 0 || start.frame !== this.id && !this.#frameSessions.has(start.frame)) return;
6205
- const download = new BrowserDownload(this.#client, start.id, start.url, start.name, this.#contextId);
6206
- this.#downloads.set(start.id, download);
6207
- this.#emitter.emit("download", download);
6208
- };
6209
- #downloadProgressHandler = (params) => {
6210
- const decoded = readBrowserDownloadProgress(params);
6211
- if (decoded === void 0) return;
6212
- const [id, progress] = decoded;
6213
- const download = this.#downloads.get(id);
6214
- if (download === void 0) return;
6215
- download.update(progress);
6216
- if (progress.status !== "pending") this.#downloads.delete(id);
6217
- };
6218
- #attachedHandler = (params) => {
6219
- const target = params["targetInfo"];
6220
- const session = params["sessionId"];
6221
- if (!isRecord(target) || !isString(target["targetId"]) || !isString(session)) return;
6222
- const category = target["type"];
6223
- if (category === "worker" || category === "service_worker" || category === "shared_worker") {
6224
- this.#attachWorker(session, target["targetId"], isString(target["url"]) ? target["url"] : "", category);
6225
- return;
6226
- }
6227
- if (category === "page") {
6228
- this.#attachPopup(session, target["targetId"], isString(target["url"]) ? target["url"] : "about:blank");
6229
- return;
6230
- }
6231
- if (category !== "iframe") return;
6232
- const frame = target["targetId"];
6233
- const attempt = this.#enableFrameSession(session);
6234
- this.#frameSessions.set(frame, attempt);
6235
- this.#frameIds.set(session, frame);
6236
- attempt.catch(() => {
6237
- if (this.#frameSessions.get(frame) === attempt) this.#frameSessions.delete(frame);
6238
- if (this.#frameIds.get(session) === frame) this.#frameIds.delete(session);
6239
- this.#detachChild(session);
6240
- });
6241
- };
6242
- #detachedHandler = (params) => {
6243
- const session = params["sessionId"];
6244
- const target = params["targetId"];
6245
- if (isString(target)) {
6246
- const worker = this.#workers.get(target);
6247
- if (worker !== void 0) {
6248
- worker.detach();
6249
- this.#workers.delete(target);
6250
- }
6251
- const popup = this.#popups.get(target);
6252
- if (popup !== void 0) {
6253
- this.#popups.delete(target);
6254
- popup.destroy().catch(() => void 0);
6255
- }
6256
- }
6257
- const frame = isString(target) ? target : isString(session) ? this.#frameIds.get(session) : void 0;
6258
- if (frame !== void 0) this.#frameSessions.delete(frame);
6259
- if (isString(session)) this.#frameIds.delete(session);
6260
- };
6167
+ #navigationResponseHandler = this.#handleNavigationResponse.bind(this);
6168
+ #destroyHandler = this.#handleDestroy.bind(this);
6169
+ #loadHandler = this.#handleLoad.bind(this);
6170
+ #frameAttachedHandler = this.#handleFrameAttached.bind(this);
6171
+ #frameNavigatedHandler = this.#handleFrameNavigated.bind(this);
6172
+ #frameDetachedHandler = this.#handleFrameDetached.bind(this);
6173
+ #dialogHandler = this.#handleDialog.bind(this);
6174
+ #chooserHandler = this.#handleChooser.bind(this);
6175
+ #consoleHandler = this.#handleConsole.bind(this);
6176
+ #errorHandler = this.#handleError.bind(this);
6177
+ #crashHandler = this.#handleCrash.bind(this);
6178
+ #downloadHandler = this.#handleDownload.bind(this);
6179
+ #downloadProgressHandler = this.#handleDownloadProgress.bind(this);
6180
+ #attachedHandler = this.#handleAttached.bind(this);
6181
+ #detachedHandler = this.#handleDetached.bind(this);
6261
6182
  constructor(client, targetId, sessionId, writer, url, frameId, contextId, opener) {
6262
6183
  super(client, sessionId, frameId ?? targetId, url ?? "about:blank", void 0, void 0, false);
6263
6184
  this.#client = client;
@@ -6717,6 +6638,131 @@ var BrowserPage = class BrowserPage extends BrowserFrame {
6717
6638
  await this.request("Page.stopLoading", void 0, timeout);
6718
6639
  } catch {}
6719
6640
  }
6641
+ #handleNavigationResponse(response) {
6642
+ if (response.frame === this.id) this.#responses?.push(response);
6643
+ }
6644
+ #handleDestroy(params) {
6645
+ if (!isString(params["targetId"]) || params["targetId"] !== this.#targetId) return;
6646
+ this.#closed = true;
6647
+ this.#release().catch(() => void 0);
6648
+ }
6649
+ #handleLoad(params) {
6650
+ if (this.#loadEvents.includes("Page.navigatedWithinDocument")) {
6651
+ const frame = params["frameId"];
6652
+ if (isString(frame) && frame === this.id) {
6653
+ this.#sameDocument = true;
6654
+ this.#resolveLoad();
6655
+ return;
6656
+ }
6657
+ }
6658
+ if (this.#loadEvents.includes("Page.frameNavigated")) {
6659
+ const frame = params["frame"];
6660
+ if (isRecord(frame) && frame["id"] === this.id) this.#resolveLoad();
6661
+ return;
6662
+ }
6663
+ if (this.#loadEvents.includes("Page.loadEventFired") || this.#loadEvents.includes("Page.domContentEventFired")) this.#resolveLoad();
6664
+ }
6665
+ #handleFrameAttached(params) {
6666
+ const frame = params["frameId"];
6667
+ const parent = params["parentFrameId"];
6668
+ if (!isString(frame)) return;
6669
+ this.#emitter.emit("attach", new BrowserFrame(this.#client, (id) => this.#resolveFrameSession(id), frame, "about:blank", isString(parent) ? parent : void 0));
6670
+ }
6671
+ #handleFrameNavigated(params) {
6672
+ const frame = params["frame"];
6673
+ if (!isRecord(frame) || !isString(frame["id"]) || !isString(frame["url"])) return;
6674
+ if (frame["id"] === this.id) {
6675
+ this.update(frame["url"]);
6676
+ this.#emitter.emit("navigate", frame["url"]);
6677
+ }
6678
+ }
6679
+ #handleFrameDetached(params) {
6680
+ const frame = params["frameId"];
6681
+ if (!isString(frame)) return;
6682
+ this.#frameSessions.delete(frame);
6683
+ this.#emitter.emit("detach", frame);
6684
+ }
6685
+ #handleDialog(params) {
6686
+ const category = params["type"];
6687
+ if (category !== "alert" && category !== "confirm" && category !== "prompt" && category !== "beforeunload" || !isString(params["message"])) return;
6688
+ this.#emitter.emit("dialog", new BrowserDialog(this, category, params["message"], isString(params["defaultPrompt"]) ? params["defaultPrompt"] : ""));
6689
+ }
6690
+ #handleChooser(params) {
6691
+ const backend = params["backendNodeId"];
6692
+ const mode = params["mode"];
6693
+ if (!isInteger(backend)) return;
6694
+ this.#emitter.emit("chooser", new BrowserFileChooser(this, backend, mode === "selectMultiple"));
6695
+ }
6696
+ #handleConsole(params) {
6697
+ const message = readBrowserConsoleMessage(params);
6698
+ if (message !== void 0) this.#emitter.emit("console", message);
6699
+ }
6700
+ #handleError(params) {
6701
+ const error = readBrowserPageError(params);
6702
+ if (error !== void 0) this.#emitter.emit("error", error);
6703
+ }
6704
+ #handleCrash() {
6705
+ this.#emitter.emit("crash");
6706
+ }
6707
+ #handleDownload(params) {
6708
+ const start = readBrowserDownloadStart(params);
6709
+ if (start === void 0 || start.frame !== this.id && !this.#frameSessions.has(start.frame)) return;
6710
+ const download = new BrowserDownload(this.#client, start.id, start.url, start.name, this.#contextId);
6711
+ this.#downloads.set(start.id, download);
6712
+ this.#emitter.emit("download", download);
6713
+ }
6714
+ #handleDownloadProgress(params) {
6715
+ const decoded = readBrowserDownloadProgress(params);
6716
+ if (decoded === void 0) return;
6717
+ const [id, progress] = decoded;
6718
+ const download = this.#downloads.get(id);
6719
+ if (download === void 0) return;
6720
+ download.update(progress);
6721
+ if (progress.status !== "pending") this.#downloads.delete(id);
6722
+ }
6723
+ #handleAttached(params) {
6724
+ const target = params["targetInfo"];
6725
+ const session = params["sessionId"];
6726
+ if (!isRecord(target) || !isString(target["targetId"]) || !isString(session)) return;
6727
+ const category = target["type"];
6728
+ if (category === "worker" || category === "service_worker" || category === "shared_worker") {
6729
+ this.#attachWorker(session, target["targetId"], isString(target["url"]) ? target["url"] : "", category);
6730
+ return;
6731
+ }
6732
+ if (category === "page") {
6733
+ this.#attachPopup(session, target["targetId"], isString(target["url"]) ? target["url"] : "about:blank");
6734
+ return;
6735
+ }
6736
+ if (category !== "iframe") return;
6737
+ const frame = target["targetId"];
6738
+ const attempt = this.#enableFrameSession(session);
6739
+ this.#frameSessions.set(frame, attempt);
6740
+ this.#frameIds.set(session, frame);
6741
+ attempt.catch(() => {
6742
+ if (this.#frameSessions.get(frame) === attempt) this.#frameSessions.delete(frame);
6743
+ if (this.#frameIds.get(session) === frame) this.#frameIds.delete(session);
6744
+ this.#detachChild(session);
6745
+ });
6746
+ }
6747
+ #handleDetached(params) {
6748
+ const session = params["sessionId"];
6749
+ const target = params["targetId"];
6750
+ if (isString(target)) {
6751
+ const worker = this.#workers.get(target);
6752
+ if (worker !== void 0) {
6753
+ worker.detach();
6754
+ this.#workers.delete(target);
6755
+ }
6756
+ const popup = this.#popups.get(target);
6757
+ if (popup !== void 0) {
6758
+ this.#popups.delete(target);
6759
+ popup.destroy().catch(() => void 0);
6760
+ }
6761
+ }
6762
+ const frame = isString(target) ? target : isString(session) ? this.#frameIds.get(session) : void 0;
6763
+ if (frame !== void 0) this.#frameSessions.delete(frame);
6764
+ if (isString(session)) this.#frameIds.delete(session);
6765
+ }
6720
6766
  #waitForLoadEvent(condition, timeout) {
6721
6767
  const eventName = condition === "commit" ? "Page.frameNavigated" : condition === "domcontentloaded" ? "Page.domContentEventFired" : "Page.loadEventFired";
6722
6768
  const deferred = Promise.withResolvers();
@@ -6818,8 +6864,8 @@ var BrowserStorageManager = class {
6818
6864
  expires: cookie.expires,
6819
6865
  http: cookie.http,
6820
6866
  secure: cookie.secure,
6821
- site: cookie.site,
6822
- partition: cookie.partition
6867
+ ...cookie.site !== void 0 ? { site: cookie.site } : {},
6868
+ ...cookie.partition !== void 0 ? { partition: cookie.partition } : {}
6823
6869
  })),
6824
6870
  origins: storage
6825
6871
  };
@@ -6967,7 +7013,7 @@ var BrowserContext = class {
6967
7013
  try {
6968
7014
  const viewport = options?.viewport ?? this.#viewport;
6969
7015
  page = await this.#attach(targetId, options?.url ?? "about:blank", viewport);
6970
- if (options?.url !== void 0 && options.url !== "about:blank") await page.navigate(options.url, { timeout: options.timeout });
7016
+ if (options?.url !== void 0 && options.url !== "about:blank") await page.navigate(options.url, { ...options.timeout !== void 0 ? { timeout: options.timeout } : {} });
6971
7017
  if (this.#closed) throw new BrowserError("Browser context closed during page creation");
6972
7018
  this.#pages.set(targetId, page);
6973
7019
  this.#emitter.emit("page", page);