puppeteer-real-browser: Can't get window instance after page load
Hey!
I’m trying to get the window instance after page page.waitForNavigation but the window is undefined.
PAGE_PUPPETEER_OPTS = {
networkIdle2Timeout: 5000,
waitUntil: 'networkidle0',
timeout: 3000000,
};
await page.waitForNavigation({ waitUntil: 'domcontentloaded' });
// await page.waitForFunction(() => window.__NUXT__ !== undefined);
// await page.waitForSelector('#__nuxt');
const windowObject = await page.evaluate(() => {
return window.__NUXT__;
});
console.log(windowObject);
result is undefined or catching timeout
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (3 by maintainers)
@nwebson It’s working. Many Thanks)
@jarmo-fi I’m glad it worked! 🎉
@pwnz22 just use the code from the article, but instead of
use
@nwebson This works nicely. Thanks!
@zfcsoftware So no need for me REBROWSER_PATCHES_RUNTIME_FIX_MODE=enableDisable
Are Events safer than somewhat simpler BroadcastChannel for bot detection?
I would suggest using
REBROWSER_PATCHES_RUNTIME_FIX_MODE=alwaysIsolatedas it’s more secure and stable.📣 I just made a post how to access main world objects from isolated context, please read it here: How to Access Main Context Objects from Isolated Context in Puppeteer & Playwright
ℹ️ TLDR: use
page.evaluateOnNewDocumentto listen for window messages and eval code, usepage.evaluateto send window message with your payload and get response from the main world. It worked just fine for several clients of mine, please let me know (discord or here) if it doesn’t work for you.I added a new test, please check it. It is possible to access the whole window object with the related method.
https://github.com/zfcsoftware/puppeteer-real-browser/blob/access-window/success2.js
https://github.com/user-attachments/assets/b31df979-d783-4a33-a4f8-331f0345db41
Please follow https://github.com/rebrowser/rebrowser-patches/issues/13 - it’s exactly the same issue. I’m gonna post a solution for this issue probably this week.