fix: do not use old utility world (#6528)

Don’t use the old utility world, as it is being destroyed later when browser reconnects to the page.

Issue: #6527
This commit is contained in:
dmitrysteblyuk 2020-11-26 12:43:42 +01:00 committed by GitHub
parent 3bf5a55289
commit fb859115c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 14 deletions

View File

@ -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 {
@ -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);

View File

@ -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 () => {