Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
n0m44 opened this issue Nov 3, 2024 · 2 comments

Comments

@n0m44
Copy link

n0m44 commented Nov 3, 2024

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
Copy link
Contributor

nwebson commented Nov 3, 2024

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

@n0m44
Copy link
Author

n0m44 commented Nov 3, 2024

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants