Repository navigation
Closed
Description
I think this is similar to #38 maybe , but I have a reproducible example.
Basically if you create a promise via page.waitForFunction to await a condition before an action like form submission, tha texecution context of that gets silently lost.
A new page.waitForFunction after the navigation with same condition works as expected; and with puppeteer even the old one correctly evaluates and resolves.
Expected
When run w/ puppeteer:
$ node index.mjs
opened https://quotes.toscrape.com/login — Quotes to Scrape
✅ New promise fullfilled correctly!
✅ Original, OLD promise fullfilled correctly!
Actual
When run w/ rebrowser:
$ node index.mjs
opened https://quotes.toscrape.com/login — Quotes to Scrape
✅ New promise fullfilled correctly!
❌ Original, OLD promise rejected! {
status: 'rejected',
reason: TimeoutError: Waiting failed: 30000ms exceeded
at new WaitTask (file:///home/raghu/Documents/node_modules/puppeteer-core/lib/esm/puppeteer/common/WaitTask.js:45:34)
at IsolatedWorld.waitForFunction (file:///home/raghu/Documents/node_modules/puppeteer-core/lib/esm/puppeteer/api/Realm.js:22:26)
at CdpFrame.waitForFunction (file:///home/raghu/Documents/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:584:43)
at CdpFrame.<anonymous> (file:///home/raghu/Documents/node_modules/puppeteer-core/lib/esm/puppeteer/util/decorators.js:101:27)
at CdpPage.waitForFunction (file:///home/raghu/Documents/dnode_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:1435:37)
at file:///home/raghu/Documents/rebrowser/index.mjs:16:27
Code to reproduce (comment / replace the library to test both).
import puppeteer from 'rebrowser-puppeteer-core';
// import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
executablePath: process.env.CHROME_PATH || '/usr/bin/chromium',
headless: false,
});
try {
const page = (await browser.pages())[0];
// sleep for 2 seconds
await new Promise(resolve => setTimeout(resolve, 2000));
await page.goto('https://quotes.toscrape.com/login', { waitUntil: 'networkidle0' });
console.log(`opened ${page.url()} — ${await page.title()}`);
const oldPromise = page.waitForFunction(() => {
console.log(`[OLD] evaluating...`);
let element = document.querySelector('h2');
console.log(`[OLD] element: ${element?.textContent}`);
if (element === null){
return false;
}
return element.textContent === 'Top Ten tags';
});
await new Promise(resolve => setTimeout(resolve, 2000));
await page.type('input[name="username"]', 'admin');
await page.type('input[name="password"]', 'password');
await page.click('input[type="submit"]');
await new Promise(resolve => setTimeout(resolve, 2000));
const newPromise = page.waitForFunction(() => {
console.log(`[NEW] evaluating...`);
let element = document.querySelector('h2');
console.log(`[NEW] element: ${element?.textContent}`);
if (element === null){
return false;
}
return element.textContent === 'Top Ten tags';
});
const [oldResult, newResult] = await Promise.allSettled([oldPromise, newPromise]);
if (newResult.status === 'rejected'){
console.error(`New promise rejected, broken script?`, newResult);
process.exit(1);
} else {
console.log(`✅ New promise fullfilled correctly!`);
}
if (oldResult.status === 'fulfilled'){
console.log(`✅ Original, OLD promise fullfilled correctly!`);
} else {
console.error(`❌ Original, OLD promise rejected!`, oldResult);
}
} finally {
await browser.close();
}Metadata
Metadata
Assignees
Labels
No labels
Activity
ckcr4lyf commentedon Sep 17, 2026
Note: in error trace it shows
puppeteer-core, thats coz I have an override set for that to rebrowser:rebrowsernet commentedon Oct 18, 2026
Thanks for the clean repro. Confirmed on 24.8.1 and 25.14.0: after a navigation the patch cleared the page's context but never restarted pending
waitForFunction()/waitForSelector()tasks, which stock Puppeteer does. With #132, your script resolves both promises. It's also a regression test now. Ships in the next release.rebrowsernet commentedon Oct 18, 2026
Released in v1.1.1:
rebrowser-puppeteer-core/rebrowser-puppeteer25.14.100,rebrowser-playwright-core/rebrowser-playwright1.64.100, andrebrowser-playwright1.64.100 on PyPI. (npm doesn't allow re-publishing 25.14.0 / 1.64.1, so this fix release uses.100.)waitForFunction()/waitForSelector()started before a navigation now resolve in the new document. Your script passes. Closing.