@skrillex1224/playwright-toolkit 3.0.52 → 3.0.54

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
@@ -6741,6 +6741,167 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
6741
6741
  }
6742
6742
  var sloveCaptcha = solveCaptcha;
6743
6743
 
6744
+ // src/internals/captcha/qbot_chaptcha.js
6745
+ var QBOT_CAPTCHA_TYPE = "30119";
6746
+ var QBOT_IMAGE_BASE_WIDTH = 310;
6747
+ var QBOT_IMAGE_BASE_HEIGHT = 155;
6748
+ var DEFAULT_QBOT_PAGE_OPTIONS = Object.freeze({
6749
+ formSelector: 'xpath=//*[@id="seccodeForm"]',
6750
+ imageSelector: 'xpath=//*[@id="seccodeForm"]//img',
6751
+ extraSelector: 'xpath=//*[@id="seccodeForm"]//*[@class="verify-bar-area"]/span',
6752
+ submitSelector: 'xpath=//*[@id="submit"]',
6753
+ refreshSelector: 'xpath=//*[@class="verify-refresh"]',
6754
+ formVisibleTimeoutMs: 1e4,
6755
+ imageVisibleTimeoutMs: 1e4,
6756
+ extraVisibleTimeoutMs: 5e3,
6757
+ payloadReadyTimeoutMs: 1e4,
6758
+ payloadPollIntervalMs: 200,
6759
+ vcSelector: "#vc",
6760
+ vcValueTimeoutMs: 8e3,
6761
+ submitLoadTimeoutMs: 3e4,
6762
+ coordinateBaseWidth: QBOT_IMAGE_BASE_WIDTH,
6763
+ coordinateBaseHeight: QBOT_IMAGE_BASE_HEIGHT,
6764
+ clickIntervalMs: 250,
6765
+ refreshVisibleTimeoutMs: 1e3,
6766
+ refreshWaitMs: 1e3,
6767
+ maxRetries: 3
6768
+ });
6769
+ var normalizeQbotCaptchaImage = (src = "") => String(src || "").split(",").pop().trim();
6770
+ var extractQbotCaptchaExtra = (text = "") => {
6771
+ const content = String(text || "").match(/【([^】]+)】/)?.[1] || "";
6772
+ return content.split(/[,,]/).map((item) => item.trim()).filter(Boolean);
6773
+ };
6774
+ var parseQbotCaptchaCoordinates = (value = "") => String(value || "").split("|").map((pair) => {
6775
+ const [x, y] = pair.split(",").map(Number);
6776
+ return Number.isFinite(x) && Number.isFinite(y) ? { x, y } : null;
6777
+ }).filter(Boolean);
6778
+ var normalizeQbotCaptchaExtraPayload = (extra = []) => Array.isArray(extra) ? extra.join(",") : String(extra || "");
6779
+ async function solveQbotCaptcha(image, extra = [], token, options = {}, dependencies = {}) {
6780
+ const { callCaptchaRecognitionApi: callCaptchaRecognitionApi2 } = dependencies;
6781
+ if (!token) {
6782
+ throw new Error("[Captcha] \u7F3A\u5C11 qbot \u9A8C\u8BC1\u7801 token\u3002");
6783
+ }
6784
+ if (typeof callCaptchaRecognitionApi2 !== "function") {
6785
+ throw new Error("[Captcha] \u7F3A\u5C11\u901A\u7528\u8BC6\u522B\u8BF7\u6C42\u51FD\u6570 callCaptchaRecognitionApi\u3002");
6786
+ }
6787
+ const response = await callCaptchaRecognitionApi2({
6788
+ apiUrl: options.apiUrl,
6789
+ token,
6790
+ type: QBOT_CAPTCHA_TYPE,
6791
+ image,
6792
+ extra: normalizeQbotCaptchaExtraPayload(extra)
6793
+ });
6794
+ return response?.data?.data ?? response?.data;
6795
+ }
6796
+ var readQbotCaptcha = async (page, config) => {
6797
+ const imageLocator = page.locator(config.imageSelector).first();
6798
+ await imageLocator.waitFor({ state: "visible", timeout: config.imageVisibleTimeoutMs });
6799
+ const extraLocator = page.locator(config.extraSelector).first();
6800
+ await extraLocator.waitFor({ state: "visible", timeout: config.extraVisibleTimeoutMs });
6801
+ const deadline = Date.now() + config.payloadReadyTimeoutMs;
6802
+ let image = "";
6803
+ let extra = [];
6804
+ while (Date.now() <= deadline) {
6805
+ image = normalizeQbotCaptchaImage(await imageLocator.getAttribute("src"));
6806
+ extra = extractQbotCaptchaExtra(await extraLocator.textContent());
6807
+ if (image && extra.length > 0) {
6808
+ return { imageLocator, image, extra };
6809
+ }
6810
+ await page.waitForTimeout(config.payloadPollIntervalMs);
6811
+ }
6812
+ if (!image) {
6813
+ throw new Error("[Captcha] qbot \u9A8C\u8BC1\u7801\u56FE\u7247\u4E3A\u7A7A\u3002");
6814
+ }
6815
+ if (extra.length === 0) {
6816
+ throw new Error("[Captcha] qbot \u9A8C\u8BC1\u7801 extra \u4E3A\u7A7A\u3002");
6817
+ }
6818
+ return { imageLocator, image, extra };
6819
+ };
6820
+ var clickQbotPoints = async (page, imageLocator, coordinates, config, deviceInput) => {
6821
+ const box = await imageLocator.boundingBox();
6822
+ if (!box) {
6823
+ throw new Error("[Captcha] qbot \u9A8C\u8BC1\u7801\u56FE\u7247\u4F4D\u7F6E\u4E0D\u53EF\u7528\u3002");
6824
+ }
6825
+ const scaleX = box.width / config.coordinateBaseWidth;
6826
+ const scaleY = box.height / config.coordinateBaseHeight;
6827
+ for (const point of coordinates) {
6828
+ await deviceInput.clickPoint(page, {
6829
+ x: box.x + point.x * scaleX,
6830
+ y: box.y + point.y * scaleY
6831
+ }, config);
6832
+ if (config.clickIntervalMs > 0) {
6833
+ await page.waitForTimeout(config.clickIntervalMs);
6834
+ }
6835
+ }
6836
+ };
6837
+ var refreshQbotCaptcha = async (page, config, deviceInput, logger18) => {
6838
+ try {
6839
+ const refreshLocator = page.locator(config.refreshSelector).first();
6840
+ if (!await waitForVisible(refreshLocator, config.refreshVisibleTimeoutMs)) return;
6841
+ await deviceInput.click(page, refreshLocator, { ...config, fallbackDomClick: true });
6842
+ if (config.refreshWaitMs > 0) {
6843
+ await page.waitForTimeout(config.refreshWaitMs);
6844
+ }
6845
+ } catch (error) {
6846
+ logger18?.warn?.(`[Captcha] qbot \u9A8C\u8BC1\u7801\u5237\u65B0\u5931\u8D25\uFF0C\u7EE7\u7EED\u629B\u51FA\u539F\u9519\u8BEF\uFF1A${error?.message || error}`);
6847
+ }
6848
+ };
6849
+ var solveQbotCaptchaAttempt = async (page, config, dependencies) => {
6850
+ const { callCaptchaRecognitionApi: callCaptchaRecognitionApi2, deviceInput } = dependencies;
6851
+ const { imageLocator, image, extra } = await readQbotCaptcha(page, config);
6852
+ const coordinateText = await solveQbotCaptcha(image, extra, config.token, config, {
6853
+ callCaptchaRecognitionApi: callCaptchaRecognitionApi2
6854
+ });
6855
+ const coordinates = parseQbotCaptchaCoordinates(coordinateText);
6856
+ if (coordinates.length === 0) {
6857
+ throw new Error("[Captcha] qbot \u9A8C\u8BC1\u7801\u5750\u6807\u4E3A\u7A7A\u3002");
6858
+ }
6859
+ await clickQbotPoints(page, imageLocator, coordinates, config, deviceInput);
6860
+ await page.waitForFunction(
6861
+ (selector) => Boolean(document.querySelector(selector)?.value),
6862
+ config.vcSelector,
6863
+ { timeout: config.vcValueTimeoutMs }
6864
+ );
6865
+ await deviceInput.click(page, page.locator(config.submitSelector).first(), {
6866
+ ...config,
6867
+ fallbackDomClick: true
6868
+ });
6869
+ await page.waitForLoadState("domcontentloaded", { timeout: config.submitLoadTimeoutMs }).catch(() => {
6870
+ });
6871
+ return true;
6872
+ };
6873
+ async function solveCaptcha2(page, options = {}, dependencies = {}) {
6874
+ const config = { ...DEFAULT_QBOT_PAGE_OPTIONS, ...options };
6875
+ const logger18 = dependencies.logger || options.logger;
6876
+ const deviceInput = dependencies.deviceInput || DeviceInput;
6877
+ if (!config.token) {
6878
+ logger18?.warn?.("[Captcha] \u7F3A\u5C11 qbot \u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
6879
+ return false;
6880
+ }
6881
+ const formLocator = page.locator(config.formSelector).first();
6882
+ if (!await waitForVisible(formLocator, config.formVisibleTimeoutMs)) {
6883
+ return false;
6884
+ }
6885
+ const maxRetries = Math.max(1, Number(config.maxRetries) || 1);
6886
+ let lastError = null;
6887
+ for (let attempt = 1; attempt <= maxRetries; attempt += 1) {
6888
+ try {
6889
+ return await solveQbotCaptchaAttempt(page, config, {
6890
+ ...dependencies,
6891
+ deviceInput
6892
+ });
6893
+ } catch (error) {
6894
+ lastError = error;
6895
+ logger18?.warn?.(`[Captcha] qbot \u9A8C\u8BC1\u7801\u8BC6\u522B\u7B2C ${attempt}/${maxRetries} \u6B21\u5931\u8D25\uFF1A${error?.message || error}`);
6896
+ if (attempt < maxRetries) {
6897
+ await refreshQbotCaptcha(page, config, deviceInput, logger18);
6898
+ }
6899
+ }
6900
+ }
6901
+ throw lastError;
6902
+ }
6903
+ var sloveCaptcha2 = solveCaptcha2;
6904
+
6744
6905
  // src/chaptcha.js
6745
6906
  var logger13 = createInternalLogger("Captcha");
6746
6907
  var DOM_MONITOR_WAIT_TIMEOUT_MS = 1e3;
@@ -6753,6 +6914,9 @@ var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
6753
6914
  var CAPTCHA_STRATEGIES = Object.freeze({
6754
6915
  bytedance: {
6755
6916
  sloveCaptcha
6917
+ },
6918
+ qbot: {
6919
+ sloveCaptcha: sloveCaptcha2
6756
6920
  }
6757
6921
  });
6758
6922
  var mergeDefinedOptions = (...sources) => {
@@ -6897,9 +7061,15 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
6897
7061
  logger: logger13
6898
7062
  });
6899
7063
  }
7064
+ async function solveQbotCaptcha2(image, extra = [], token, options = {}) {
7065
+ return solveQbotCaptcha(image, extra, token, options, {
7066
+ callCaptchaRecognitionApi
7067
+ });
7068
+ }
6900
7069
  var Captcha = {
6901
7070
  useCaptchaMonitor,
6902
- solveCaptchaWithStrategy
7071
+ solveCaptchaWithStrategy,
7072
+ solveQbotCaptcha: solveQbotCaptcha2
6903
7073
  };
6904
7074
 
6905
7075
  // src/mutation.js