Skip to content

Commit

Permalink
waitTask should survive cross-process navigation (#435)
Browse files Browse the repository at this point in the history
In case of cross-process navigation, we receive a context
which is immediately getting destroyed.

Fixes #396.
  • Loading branch information
aslushnikov committed Aug 21, 2017
1 parent c1731dd commit afd9012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/FrameManager.js
Expand Up @@ -419,6 +419,11 @@ class WaitTask {
if (error && error.message.includes('Execution context was destroyed'))
return;

// We could have tried to evaluate in a context which was already
// destroyed.
if (error && error.message.includes('Cannot find context with specified id'))
return;

if (error)
this._reject(error);
else
Expand Down
7 changes: 4 additions & 3 deletions test/test.js
Expand Up @@ -32,6 +32,7 @@ const OUTPUT_DIR = path.join(__dirname, 'output');

const PORT = 8907;
const PREFIX = 'http://localhost:' + PORT;
const CROSS_PROCESS_PREFIX = 'http://127.0.0.1:' + PORT;
const EMPTY_PAGE = PREFIX + '/empty.html';
const HTTPS_PORT = 8908;
const HTTPS_PREFIX = 'https://localhost:' + HTTPS_PORT;
Expand Down Expand Up @@ -275,7 +276,7 @@ describe('Page', function() {
await page.goto(EMPTY_PAGE);
let mainFrame = page.mainFrame();
expect(await mainFrame.evaluate(() => window.location.href)).toContain('localhost');
await page.goto('http://127.0.0.1:' + PORT + '/empty.html');
await page.goto(CROSS_PROCESS_PREFIX + '/empty.html');
expect(await mainFrame.evaluate(() => window.location.href)).toContain('127');
}));
});
Expand Down Expand Up @@ -423,14 +424,14 @@ describe('Page', function() {
expect(waitError).toBeTruthy();
expect(waitError.message).toContain('waitForSelector failed: frame got detached.');
}));
it('should survive navigation', SX(async function() {
it('should survive cross-process navigation', SX(async function() {
let boxFound = false;
let waitForSelector = page.waitForSelector('.box').then(() => boxFound = true);
await page.goto(EMPTY_PAGE);
expect(boxFound).toBe(false);
await page.reload();
expect(boxFound).toBe(false);
await page.goto(PREFIX + '/grid.html');
await page.goto(CROSS_PROCESS_PREFIX + '/grid.html');
await waitForSelector;
expect(boxFound).toBe(true);
}));
Expand Down

0 comments on commit afd9012

Please sign in to comment.