rebrowser / rebrowser-patches

Collection of patches for puppeteer and playwright to avoid automation detection and leaks. Helps to avoid Cloudflare and DataDome CAPTCHA pages. Easy to patch/unpatch, can be enabled/disabled on demand.
https://rebrowser.net
304 stars 27 forks source link

failed: [rebrowser-patches] acquireContextId failed on chrome extensions pages #59

Open n0m44 opened 1 day ago

n0m44 commented 1 day ago

Hi! I tried to use rebrowser-puppeteer on the chrome extension page (Metamask in the example) and when I try to get any element, I get an error:

 Error: Waiting for selector `body` failed: [rebrowser-patches] acquireContextId failed
    at ExecutionContext.acquireContextId (/home/user/Desktop/qwe/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:470:23)
    at async IsolatedWorld.adoptBackendNode (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:229:3)
    at async IsolatedWorld.transferHandle (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:65:1)
    at async Function.waitFor (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/common/QueryHandler.ts:204:14)
    at async CdpFrame.waitForSelector (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/api/Frame.ts:729:13)
    at async CdpPage.waitForSelector (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/api/Page.ts:2942:12)

code snippet:

import puppeteer from "rebrowser-puppeteer";

const run = async () => {
  const browser = await puppeteer.launch({
    headless: false,
    ignoreDefaultArgs: true,
    args: [
      '--window-size=1920,1080',
      '--flag-switches-begin',
      '--flag-switches-end',
      '--origin-trial-disabled-features=WebGPU',
      '--disable-blink-features=AutomationControlled',
      `--user-data-dir=blablaToDelete`,
    ],
  });

  const page = await browser.newPage();

  await page.goto('chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#onboarding/welcome')

  await page.waitForSelector('body');
}

run();

versions:

    "rebrowser-puppeteer": "^23.6.101",
    "rebrowser-puppeteer-core": "^23.6.101",
    "typescript": "^5.6.3"

In addition to the attention: Sometimes the chrome extension window may appear while the browser is running, I hope it will also work after the fix

Reproduce steps:

  1. Make first run of snippet
  2. Manually install metamask https://chromewebstore.google.com/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn
  3. Re-run script again
nwebson commented 1 day ago

Please run it with REBROWSER_PATCHES_DEBUG=1 and show the full log here. That would be very helpful.

n0m44 commented 1 day ago

@nwebson ty for answer

log:

[rebrowser-patches][FrameManager] initialize
[rebrowser-patches] onFrameNavigated, navigationType = Navigation, id = 0E20ABA982C5E9EF4152E9AC573C5CF2, url = about:blank
[rebrowser-patches] onFrameNavigated, navigationType = Navigation, id = 0E20ABA982C5E9EF4152E9AC573C5CF2, url = chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html
[rebrowser-patches] onFrameNavigated, navigationType = Navigation, id = 046C3F9CC0DFEEAB23747745208B41F8, url = about:blank
[rebrowser-patches][acquireContextId] id = -2, name = util, fixMode = addBinding, tryCount = 1
[rebrowser-patches][acquireContextId] Page.createIsolatedWorld result: { executionContextId: 2 }
[rebrowser-patches][acquireContextId] id = -1, name = undefined, fixMode = addBinding, tryCount = 1
[rebrowser-patches][acquireContextId] binding name = oiajfd6y6obzong34nb
[rebrowser-patches][acquireContextId] failed, try again (tryCount = 1)
[rebrowser-patches][acquireContextId] id = -1, name = undefined, fixMode = addBinding, tryCount = 2
[rebrowser-patches][acquireContextId] binding name = j2q6wrrbl0kdff
[rebrowser-patches][acquireContextId] failed, try again (tryCount = 2)
[rebrowser-patches][acquireContextId] id = -1, name = undefined, fixMode = addBinding, tryCount = 3
[rebrowser-patches][acquireContextId] binding name = an6uzc6f5tt5tr1o0mh
/home/user/Desktop/qwe/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:470
                throw new Error('[rebrowser-patches] acquireContextId failed');
                      ^
Error: Waiting for selector `body` failed: [rebrowser-patches] acquireContextId failed
    at ExecutionContext.acquireContextId (/home/user/Desktop/qwe/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:470:23)
    at async IsolatedWorld.adoptBackendNode (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:229:3)
    at async IsolatedWorld.transferHandle (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:65:1)
    at async Function.waitFor (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/common/QueryHandler.ts:204:14)
    at async CdpFrame.waitForSelector (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/api/Frame.ts:729:13)
    at async CdpPage.waitForSelector (/home/user/Desktop/qwe/node_modules/puppeteer-core/src/api/Page.ts:2942:12)