mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(evaluate): throw error when page reloads during page.evaluate. (#2073)
Fixes #2021.
This commit is contained in:
parent
66887743ea
commit
fc2a10440f
@ -44,7 +44,11 @@ class ExecutionContext {
|
||||
*/
|
||||
async evaluate(pageFunction, ...args) {
|
||||
const handle = await this.evaluateHandle(pageFunction, ...args);
|
||||
const result = await handle.jsonValue().catch(error => undefined);
|
||||
const result = await handle.jsonValue().catch(error => {
|
||||
if (error.message.includes('Object reference chain is too long'))
|
||||
return;
|
||||
throw error;
|
||||
});
|
||||
await handle.dispose();
|
||||
return result;
|
||||
}
|
||||
|
19
test/test.js
19
test/test.js
@ -425,6 +425,16 @@ describe('Page', function() {
|
||||
const result = await page.evaluate(() => 7 * 3);
|
||||
expect(result).toBe(21);
|
||||
});
|
||||
it('should throw when evaluation triggers reload', async({page, server}) => {
|
||||
let error = null;
|
||||
await page.evaluate(() => {
|
||||
location.reload();
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(1), 0);
|
||||
});
|
||||
}).catch(e => error = e);
|
||||
expect(error.message).toContain('Protocol error');
|
||||
});
|
||||
it('should await promise', async({page, server}) => {
|
||||
const result = await page.evaluate(() => Promise.resolve(8 * 7));
|
||||
expect(result).toBe(56);
|
||||
@ -486,6 +496,15 @@ describe('Page', function() {
|
||||
const result = await page.evaluate(() => window);
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
it('should fail for circular object', async({page, server}) => {
|
||||
const result = await page.evaluate(() => {
|
||||
const a = {};
|
||||
const b = {a};
|
||||
a.b = b;
|
||||
return a;
|
||||
});
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
it('should accept a string', async({page, server}) => {
|
||||
const result = await page.evaluate('1 + 2');
|
||||
expect(result).toBe(3);
|
||||
|
Loading…
Reference in New Issue
Block a user