Skip to content

Commit

Permalink
fix: do not use old utility world (#6528)
Browse files Browse the repository at this point in the history
Don’t use the old utility world, as it is being destroyed later when browser reconnects to the page.

Issue: #6527
  • Loading branch information
dmitrysteblyuk committed Nov 26, 2020
1 parent 3bf5a55 commit fb85911
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/common/FrameManager.ts
Expand Up @@ -322,18 +322,19 @@ export class FrameManager extends EventEmitter {
await this._client.send('Page.addScriptToEvaluateOnNewDocument', {
source: `//# sourceURL=${EVALUATION_SCRIPT_URL}`,
worldName: name,
}),
await Promise.all(
this.frames().map((frame) =>
this._client
.send('Page.createIsolatedWorld', {
frameId: frame._id,
grantUniveralAccess: true,
worldName: name,
})
.catch(debugError)
)
); // frames might be removed before we send this
});
// Frames might be removed before we send this.
await Promise.all(
this.frames().map((frame) =>
this._client
.send('Page.createIsolatedWorld', {
frameId: frame._id,
worldName: name,
grantUniveralAccess: true,
})
.catch(debugError)
)
);
}

_onFrameNavigatedWithinDocument(frameId: string, url: string): void {
Expand Down Expand Up @@ -369,8 +370,6 @@ export class FrameManager extends EventEmitter {
world = frame._secondaryWorld;
}
}
if (contextPayload.auxData && contextPayload.auxData['type'] === 'isolated')
this._isolatedWorlds.add(contextPayload.name);
const context = new ExecutionContext(this._client, contextPayload, world);
if (world) world._setContext(context);
this._contextIdToContext.set(contextPayload.id, context);
Expand Down
19 changes: 19 additions & 0 deletions test/launcher.spec.ts
Expand Up @@ -589,6 +589,25 @@ describe('Launcher specs', function () {
await browserOne.close();
}
);
// @see https://github.com/puppeteer/puppeteer/issues/6527
it('should be able to reconnect', async () => {
const { puppeteer, server } = getTestState();
const browserOne = await puppeteer.launch();
const browserWSEndpoint = browserOne.wsEndpoint();
const pageOne = await browserOne.newPage();
await pageOne.goto(server.EMPTY_PAGE);
browserOne.disconnect();

const browserTwo = await puppeteer.connect({ browserWSEndpoint });
const pages = await browserTwo.pages();
const pageTwo = pages.find((page) => page.url() === server.EMPTY_PAGE);
await pageTwo.reload();
const bodyHandle = await pageTwo.waitForSelector('body', {
timeout: 10000,
});
await bodyHandle.dispose();
await browserTwo.close();
});
});
describe('Puppeteer.executablePath', function () {
itOnlyRegularInstall('should work', async () => {
Expand Down

0 comments on commit fb85911

Please sign in to comment.