@skrillex1224/playwright-toolkit 2.1.257 → 2.1.259

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.
package/dist/index.js CHANGED
@@ -2275,7 +2275,7 @@ async function createApifyKit() {
2275
2275
  options
2276
2276
  }
2277
2277
  );
2278
- await Actor2.fail(`Run Step ${step} \u5931\u8D25 (\u5DF2\u91CD\u8BD5 ${retryTimes} \u6B21): ${finalError.message}`);
2278
+ await Actor2.fail(`Run Step ${step} \u5931\u8D25 (\u5DF2\u91CD\u8BD5 ${retryTimes} \u6B21): ${finalError.message} | url: ${page.url()}`);
2279
2279
  } else {
2280
2280
  throw finalError;
2281
2281
  }
@@ -2473,7 +2473,8 @@ function buildFingerprintOptions({ locale = BASE_CONFIG.locale, browserMajorVers
2473
2473
  browsers: browserDescriptor,
2474
2474
  devices: [resolvedDevice],
2475
2475
  operatingSystems: resolvedDevice === Device.Mobile ? ["android"] : ["windows", "macos", "linux"],
2476
- locales: [locale]
2476
+ locales: [locale],
2477
+ strict: true
2477
2478
  };
2478
2479
  if (resolvedDevice === Device.Mobile) {
2479
2480
  options.screen = {
@@ -4527,7 +4528,7 @@ var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
4527
4528
  return { byPassDomains, enableProxy, proxyUrl };
4528
4529
  };
4529
4530
  var parseChromeMajorVersion = (rawValue = "") => {
4530
- const match = String(rawValue || "").match(/Chrome\/(\d+)/i);
4531
+ const match = String(rawValue || "").match(/(?:Chrome|Chromium)(?:\/|\s+(?:for Testing\s+)?)(\d+)/i);
4531
4532
  return match ? Number(match[1] || 0) : 0;
4532
4533
  };
4533
4534
  var resolveLauncherExecutablePath = (launcher) => {
@@ -4576,6 +4577,36 @@ var buildFingerprintGenerator = ({ locale, browserMajorVersion, device }) => {
4576
4577
  })
4577
4578
  );
4578
4579
  };
4580
+ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
4581
+ const requestedBrowserMajorVersion = Number(browserMajorVersion || 0);
4582
+ const generator = buildFingerprintGenerator({
4583
+ locale,
4584
+ browserMajorVersion: requestedBrowserMajorVersion,
4585
+ device
4586
+ });
4587
+ try {
4588
+ return {
4589
+ fingerprint: generator.getFingerprint(),
4590
+ exactBrowserMajorVersion: requestedBrowserMajorVersion > 0
4591
+ };
4592
+ } catch (error) {
4593
+ if (requestedBrowserMajorVersion <= 0) {
4594
+ throw error;
4595
+ }
4596
+ logger8.warn(
4597
+ `\u5F53\u524D\u6D4F\u89C8\u5668\u5927\u7248\u672C ${requestedBrowserMajorVersion} \u65E0\u53EF\u7528 strict \u6307\u7EB9\u6837\u672C\uFF0C\u9000\u56DE\u4E0D\u7ED1\u5B9A\u5927\u7248\u672C\u751F\u6210: ${error?.message || error}`
4598
+ );
4599
+ }
4600
+ const fallbackGenerator = buildFingerprintGenerator({
4601
+ locale,
4602
+ browserMajorVersion: 0,
4603
+ device
4604
+ });
4605
+ return {
4606
+ fingerprint: fallbackGenerator.getFingerprint(),
4607
+ exactBrowserMajorVersion: false
4608
+ };
4609
+ };
4579
4610
  var buildReplayableBrowserProfile = (runtimeState, launcher) => {
4580
4611
  const device = resolveRuntimeDevice(runtimeState);
4581
4612
  if (!runtimeState || !RuntimeEnv.hasLoginState(runtimeState)) {
@@ -4591,12 +4622,12 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
4591
4622
  const needsDeviceRebuild = storedDevice ? storedDevice !== device : device === Device.Mobile;
4592
4623
  const needsRebuild = !browserProfileCore?.fingerprint || Object.keys(browserProfileCore.fingerprint || {}).length === 0 || needsDeviceRebuild || currentBrowserMajorVersion > 0 && storedBrowserMajorVersion > 0 && storedBrowserMajorVersion !== currentBrowserMajorVersion;
4593
4624
  if (needsRebuild) {
4594
- const generator = buildFingerprintGenerator({
4625
+ const generated = generateFingerprintForCore({
4595
4626
  locale,
4596
4627
  browserMajorVersion: currentBrowserMajorVersion,
4597
4628
  device
4598
4629
  });
4599
- const fingerprint = generator.getFingerprint();
4630
+ const fingerprint = generated.fingerprint;
4600
4631
  const fingerprintBrowserMajorVersion = parseChromeMajorVersion(fingerprint?.fingerprint?.navigator?.userAgent || "");
4601
4632
  browserProfileCore = {
4602
4633
  fingerprint,
@@ -4608,7 +4639,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
4608
4639
  };
4609
4640
  nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
4610
4641
  logger8.info(
4611
- `\u5DF2\u751F\u6210\u6D4F\u89C8\u5668\u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | device=${device} | version=${browserProfileCore.browser_major_version || "-"} | timezone=${timezoneId}`
4642
+ `\u5DF2\u751F\u6210\u6D4F\u89C8\u5668\u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | device=${device} | version=${browserProfileCore.browser_major_version || "-"} | fingerprintVersion=${fingerprintBrowserMajorVersion || "-"} | exactVersion=${generated.exactBrowserMajorVersion ? "true" : "false"} | timezone=${timezoneId}`
4612
4643
  );
4613
4644
  return { runtimeState: nextState, browserProfileCore };
4614
4645
  }
@@ -4630,33 +4661,36 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
4630
4661
  browserProfileCore: normalizedBrowserProfileCore
4631
4662
  };
4632
4663
  };
4633
- var applyDevicePageOptions = (pageOptions = {}, { device = Device.Desktop, fingerprint = null } = {}) => {
4664
+ var applyFingerprintPageOptions = (pageOptions = {}, { fingerprintWithHeaders = null, locale = "", timezoneId = "" } = {}) => {
4634
4665
  if (!pageOptions || typeof pageOptions !== "object") return;
4635
- const resolvedDevice = normalizeDevice(device);
4666
+ const fingerprint = fingerprintWithHeaders?.fingerprint || fingerprintWithHeaders;
4667
+ if (!fingerprint || typeof fingerprint !== "object") return;
4636
4668
  const screen = fingerprint?.screen || {};
4669
+ const navigatorFingerprint = fingerprint?.navigator || {};
4670
+ const headers = fingerprintWithHeaders?.headers || {};
4671
+ const userAgent = String(navigatorFingerprint.userAgent || headers["user-agent"] || "").trim();
4672
+ const width = Number(screen.width || 0);
4673
+ const height = Number(screen.height || 0);
4637
4674
  const dpr = Number(screen.devicePixelRatio || 0);
4638
- if (resolvedDevice === Device.Mobile) {
4639
- pageOptions.isMobile = true;
4640
- pageOptions.hasTouch = true;
4641
- pageOptions.deviceScaleFactor = dpr > 0 ? dpr : 2;
4642
- if (!pageOptions.viewport) {
4643
- pageOptions.viewport = {
4644
- width: Number(screen.width || 390),
4645
- height: Number(screen.height || 844)
4646
- };
4647
- }
4648
- if (!pageOptions.screen) {
4649
- pageOptions.screen = {
4650
- width: Number(screen.width || pageOptions.viewport.width || 390),
4651
- height: Number(screen.height || pageOptions.viewport.height || 844)
4652
- };
4653
- }
4654
- return;
4675
+ const maxTouchPoints = Number(navigatorFingerprint.maxTouchPoints || 0);
4676
+ const isMobile = navigatorFingerprint.userAgentData?.mobile === true || headers["sec-ch-ua-mobile"] === "?1" || /Mobile|Android/i.test(userAgent);
4677
+ if (userAgent) {
4678
+ pageOptions.userAgent = userAgent;
4679
+ }
4680
+ if (width > 0 && height > 0) {
4681
+ pageOptions.viewport = { width, height };
4682
+ pageOptions.screen = { width, height };
4655
4683
  }
4656
- pageOptions.isMobile = false;
4657
- pageOptions.hasTouch = false;
4658
- if (!pageOptions.deviceScaleFactor) {
4659
- pageOptions.deviceScaleFactor = dpr > 0 ? dpr : 1;
4684
+ pageOptions.isMobile = isMobile;
4685
+ pageOptions.hasTouch = maxTouchPoints > 0;
4686
+ if (dpr > 0) {
4687
+ pageOptions.deviceScaleFactor = dpr;
4688
+ }
4689
+ if (locale) {
4690
+ pageOptions.locale = locale;
4691
+ }
4692
+ if (timezoneId) {
4693
+ pageOptions.timezoneId = timezoneId;
4660
4694
  }
4661
4695
  };
4662
4696
  var buildReplayBrowserPoolOptions = (browserProfileCore) => {
@@ -4670,30 +4704,10 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
4670
4704
  prePageCreateHooks: [
4671
4705
  (_pageId, _browserController, pageOptions = {}) => {
4672
4706
  if (!pageOptions || typeof pageOptions !== "object") return;
4673
- const screen = fingerprint.screen || {};
4674
- const userAgent = String(fingerprint.navigator?.userAgent || "").trim();
4675
- if (userAgent) {
4676
- pageOptions.userAgent = userAgent;
4677
- }
4678
- if (Number(screen.width || 0) > 0 && Number(screen.height || 0) > 0) {
4679
- pageOptions.viewport = {
4680
- width: Number(screen.width),
4681
- height: Number(screen.height)
4682
- };
4683
- pageOptions.screen = {
4684
- width: Number(screen.width),
4685
- height: Number(screen.height)
4686
- };
4687
- }
4688
- if (browserProfileCore.locale) {
4689
- pageOptions.locale = browserProfileCore.locale;
4690
- }
4691
- if (browserProfileCore.timezone_id) {
4692
- pageOptions.timezoneId = browserProfileCore.timezone_id;
4693
- }
4694
- applyDevicePageOptions(pageOptions, {
4695
- device: browserProfileCore.device,
4696
- fingerprint
4707
+ applyFingerprintPageOptions(pageOptions, {
4708
+ fingerprintWithHeaders,
4709
+ locale: browserProfileCore.locale,
4710
+ timezoneId: browserProfileCore.timezone_id
4697
4711
  });
4698
4712
  }
4699
4713
  ],
@@ -4811,15 +4825,14 @@ var Launch = {
4811
4825
  })
4812
4826
  },
4813
4827
  prePageCreateHooks: [
4814
- (_pageId, _browserController, pageOptions = {}) => {
4815
- applyDevicePageOptions(pageOptions, { device });
4816
- if (launchLocale) {
4817
- pageOptions.locale = launchLocale;
4818
- }
4828
+ (_pageId, browserController, pageOptions = {}) => {
4829
+ const fingerprintWithHeaders = browserController?.launchContext?.fingerprint;
4819
4830
  const timezoneId = AntiCheat.getBaseConfig().timezoneId;
4820
- if (timezoneId) {
4821
- pageOptions.timezoneId = timezoneId;
4822
- }
4831
+ applyFingerprintPageOptions(pageOptions, {
4832
+ fingerprintWithHeaders,
4833
+ locale: launchLocale,
4834
+ timezoneId
4835
+ });
4823
4836
  }
4824
4837
  ]
4825
4838
  },