patchright-core 1.52.3 → 1.52.4

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.
@@ -552,7 +552,8 @@ class RouteImpl {
552
552
  let injectionHTML = "";
553
553
  allInjections.forEach((script) => {
554
554
  let scriptId = import_crypto.default.randomBytes(22).toString("hex");
555
- injectionHTML += `<script class="${this._page._delegate.initScriptTag}" nonce="${scriptNonce}" type="text/javascript">document.getElementById("${scriptId}")?.remove();${script.source}</script>`;
555
+ let scriptSource = script.source || script;
556
+ injectionHTML += `<script class="${this._page._delegate.initScriptTag}" nonce="${scriptNonce}" type="text/javascript">document.getElementById("${scriptId}")?.remove();${scriptSource}</script>`;
556
557
  });
557
558
  if (response.isBase64) {
558
559
  response.isBase64 = false;
@@ -756,7 +756,7 @@ class Frame extends import_instrumentation.SdkObject {
756
756
  } catch (e) {
757
757
  return "internal:continuepolling";
758
758
  }
759
- });
759
+ }, "returnOnNotResolved");
760
760
  return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
761
761
  }
762
762
  async dispatchEvent(metadata, selector, type, eventInit = {}, options = {}, scope) {
@@ -797,6 +797,7 @@ class Frame extends import_instrumentation.SdkObject {
797
797
  const resultPromise = await controller.run(async (progress) => {
798
798
  progress.log("waiting for " + this._asLocator(selector));
799
799
  const promise = await this._retryWithProgressIfNotConnected(progress, selector, false, false, async (result) => {
800
+ if (!result) return 0;
800
801
  const handle = result[0];
801
802
  const handles = result[1];
802
803
  return handle ? handles.length : 0;
@@ -978,7 +979,7 @@ class Frame extends import_instrumentation.SdkObject {
978
979
  return result;
979
980
  }
980
981
  async retryWithProgressAndTimeouts(progress, timeouts, action) {
981
- const continuePolling2 = Symbol("continuePolling");
982
+ const continuePolling3 = Symbol("continuePolling");
982
983
  timeouts = [0, ...timeouts];
983
984
  let timeoutIndex = 0;
984
985
  while (progress.isRunning()) {
@@ -992,8 +993,8 @@ class Frame extends import_instrumentation.SdkObject {
992
993
  }
993
994
  progress.throwIfAborted();
994
995
  try {
995
- const result = await action(continuePolling2);
996
- if (result === continuePolling2)
996
+ const result = await action(continuePolling3);
997
+ if (result === continuePolling3)
997
998
  continue;
998
999
  return result;
999
1000
  } catch (e) {
@@ -1016,15 +1017,18 @@ class Frame extends import_instrumentation.SdkObject {
1016
1017
  }
1017
1018
  async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action, returnAction) {
1018
1019
  progress.log("waiting for " + this._asLocator(selector));
1019
- return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling2) => {
1020
+ return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling3) => {
1020
1021
  if (performActionPreChecks) await this._page.performActionPreChecks(progress);
1021
1022
  const resolved = await this.selectors.resolveInjectedForSelector(selector, {
1022
1023
  strict
1023
1024
  });
1024
1025
  progress.throwIfAborted();
1025
1026
  if (!resolved) {
1026
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") return null;
1027
- return continuePolling2;
1027
+ if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1028
+ const result2 = await action(null);
1029
+ return result2 === "internal:continuepolling" ? continuePolling2 : result2;
1030
+ }
1031
+ return continuePolling3;
1028
1032
  }
1029
1033
  try {
1030
1034
  var client = this._page._delegate._sessionForFrame(resolved.frame)._client;
@@ -1042,8 +1046,11 @@ class Frame extends import_instrumentation.SdkObject {
1042
1046
  const documentScope = new dom.ElementHandle(context, documentNode.result.objectId);
1043
1047
  const currentScopingElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, resolved.info.parsed);
1044
1048
  if (currentScopingElements.length == 0) {
1045
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") return null;
1046
- return continuePolling2;
1049
+ if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1050
+ const result2 = await action(null);
1051
+ return result2 === "internal:continuepolling" ? continuePolling2 : result2;
1052
+ }
1053
+ return continuePolling3;
1047
1054
  }
1048
1055
  const resultElement = currentScopingElements[0];
1049
1056
  if (currentScopingElements.length > 1) {
@@ -1071,9 +1078,9 @@ class Frame extends import_instrumentation.SdkObject {
1071
1078
  }
1072
1079
  if (result === "error:notconnected") {
1073
1080
  progress.log("element was detached from the DOM, retrying");
1074
- return continuePolling2;
1081
+ return continuePolling3;
1075
1082
  } else if (result === "internal:continuepolling") {
1076
- return continuePolling2;
1083
+ return continuePolling3;
1077
1084
  }
1078
1085
  return result;
1079
1086
  } finally {
@@ -1214,6 +1221,7 @@ class Frame extends import_instrumentation.SdkObject {
1214
1221
  return await controller.run(async (progress) => {
1215
1222
  progress.log("waiting for " + this._asLocator(selector));
1216
1223
  const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async (handle) => {
1224
+ if (!handle) return false;
1217
1225
  if (handle.parentNode.constructor.name == "ElementHandle") {
1218
1226
  return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
1219
1227
  const state = handle2 ? injected.elementState(handle2, "visible") : {
@@ -1342,11 +1350,11 @@ class Frame extends import_instrumentation.SdkObject {
1342
1350
  if (timeout < 0)
1343
1351
  return { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log), timedOut: true, received: lastIntermediateResult.received };
1344
1352
  return await new import_progress.ProgressController(metadata, this).run(async (progress) => {
1345
- return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling2) => {
1353
+ return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling3) => {
1346
1354
  await this._page.performActionPreChecks(progress);
1347
1355
  const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult);
1348
1356
  if (matches === options.isNot) {
1349
- return continuePolling2;
1357
+ return continuePolling3;
1350
1358
  }
1351
1359
  return { matches, received };
1352
1360
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patchright-core",
3
- "version": "1.52.3",
3
+ "version": "1.52.4",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": {
6
6
  "type": "git",