From 99f5c71f73a5f6d77700574de32c57b136f97b8d Mon Sep 17 00:00:00 2001 From: Cody Nguyen Date: Wed, 17 Apr 2024 14:12:50 +0700 Subject: [PATCH] Fix `Error: Failed to add page binding with name ___pepr_cs: window['___pepr_cs'] already exists!` When page.solveRecaptchas() is called multiple times, an error is thrown ``` Error: Failed to add page binding with name ___pepr_cs: window['___pepr_cs'] already exists! ``` In my test I use puppeteer@14.4.1 with its default Chrome, puppeteer-extra@3.3.4 and puppeteer-extra-plugin-recaptcha@3.6.8. I haven't tried other versions. --- packages/puppeteer-extra-plugin-recaptcha/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/puppeteer-extra-plugin-recaptcha/src/index.ts b/packages/puppeteer-extra-plugin-recaptcha/src/index.ts index 49bac2ee..b91d02f2 100644 --- a/packages/puppeteer-extra-plugin-recaptcha/src/index.ts +++ b/packages/puppeteer-extra-plugin-recaptcha/src/index.ts @@ -170,7 +170,11 @@ export class PuppeteerExtraPluginRecaptcha extends PuppeteerExtraPlugin { if (this.contentScriptDebug.enabled) { if ('exposeFunction' in page) { - await page.exposeFunction(this.debugBindingName, onDebugBindingCalled) + try { + await page.exposeFunction(this.debugBindingName, onDebugBindingCalled); + } catch (err) { + this.debug('`debugBindingName` function is already exposed'); + } } } // Even without a recaptcha script tag we're trying, just in case.