From 4e787f88b282592bfe4fd1707152386b0c8f26f3 Mon Sep 17 00:00:00 2001 From: zfcsoftware Date: Mon, 9 Sep 2024 22:27:50 +0300 Subject: [PATCH] Implemented a fix for puppeteer-extra plugins not working when using a proxy. --- lib/cjs/module/pageController.js | 12 ++++++------ lib/esm/module/pageController.mjs | 12 ++++++------ package.json | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/cjs/module/pageController.js b/lib/cjs/module/pageController.js index 267754f..1f6ff80 100644 --- a/lib/cjs/module/pageController.js +++ b/lib/cjs/module/pageController.js @@ -10,12 +10,6 @@ function getRandomInt(min, max) { async function pageController({ browser, page, proxy, turnstile, xvfbsession, pid, plugins, killProcess = false, chrome }) { - if (plugins.length > 0) { - for (const plugin of plugins) { - plugin.onPageCreated(page) - } - } - let solveStatus = turnstile page.on('close', () => { @@ -44,6 +38,12 @@ async function pageController({ browser, page, proxy, turnstile, xvfbsession, pi if (proxy.username && proxy.password) await page.authenticate({ username: proxy.username, password: proxy.password }); + if (plugins.length > 0) { + for (const plugin of plugins) { + plugin.onPageCreated(page) + } + } + await page.evaluateOnNewDocument(() => { Object.defineProperty(MouseEvent.prototype, 'screenX', { get: function () { diff --git a/lib/esm/module/pageController.mjs b/lib/esm/module/pageController.mjs index 9bccff2..1675630 100644 --- a/lib/esm/module/pageController.mjs +++ b/lib/esm/module/pageController.mjs @@ -10,12 +10,6 @@ function getRandomInt(min, max) { export async function pageController({ browser, page, proxy, turnstile, xvfbsession, pid, plugins, killProcess = false, chrome }) { - if (plugins.length > 0) { - for (const plugin of plugins) { - plugin.onPageCreated(page) - } - } - let solveStatus = turnstile page.on('close', () => { @@ -44,6 +38,12 @@ export async function pageController({ browser, page, proxy, turnstile, xvfbsess if (proxy.username && proxy.password) await page.authenticate({ username: proxy.username, password: proxy.password }); + if (plugins.length > 0) { + for (const plugin of plugins) { + plugin.onPageCreated(page) + } + } + await page.evaluateOnNewDocument(() => { Object.defineProperty(MouseEvent.prototype, 'screenX', { get: function () { diff --git a/package.json b/package.json index 123fa6e..7f3fe0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "puppeteer-real-browser", - "version": "1.3.11", + "version": "1.3.12", "description": "This package is designed to bypass puppeteer's bot-detecting captchas such as Cloudflare. It acts like a real browser and can be managed with puppeteer.", "main": "lib/cjs/index.js", "module": "lib/esm/index.mjs",