mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(page): fix race condition in WaitTask (#2739)
This patch eliminates a common race condition with WaitTask, that happens when predicate function gets resolved right before the execution context gets destroyed. This situation results in a "Cannot find context with specified id undefined" exception. Credits go to @jakub300 for his wonderful [investigation](https://github.com/GoogleChrome/puppeteer/issues/1325#issuecomment-395472092). Fixes #1325.
This commit is contained in:
parent
ed7a26cc95
commit
ddfdaf97c5
@ -869,7 +869,9 @@ class WaitTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ignore timeouts in pageScript - we track timeouts ourselves.
|
// Ignore timeouts in pageScript - we track timeouts ourselves.
|
||||||
if (!error && await this._frame.evaluate(s => !s, success)) {
|
// If the frame's execution context has already changed, `frame.evaluate` will
|
||||||
|
// throw an error - ignore this predicate run altogether.
|
||||||
|
if (!error && await this._frame.evaluate(s => !s, success).catch(e => true)) {
|
||||||
await success.dispose();
|
await success.dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,14 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
await page.evaluate(() => window.__FOO = 1);
|
await page.evaluate(() => window.__FOO = 1);
|
||||||
await watchdog;
|
await watchdog;
|
||||||
});
|
});
|
||||||
|
it('should work when resolved right before execution context disposal', async({page, server}) => {
|
||||||
|
await page.evaluateOnNewDocument(() => window.__RELOADED = true);
|
||||||
|
await page.waitForFunction(() => {
|
||||||
|
if (!window.__RELOADED)
|
||||||
|
window.location.reload();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should poll on interval', async({page, server}) => {
|
it('should poll on interval', async({page, server}) => {
|
||||||
let success = false;
|
let success = false;
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
Loading…
Reference in New Issue
Block a user