Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class FFPage implements PageDelegate {
this._contextIdToContext = new Map();
this._page = new Page(this, browserContext);
this._networkManager = new FFNetworkManager(session, this._page);
this._page.on(Events.Page.FrameDetached, frame => this._removeContextsForFrame(frame));
this._eventListeners = [
helper.addEventListener(this._session, 'Page.eventFired', this._onEventFired.bind(this)),
helper.addEventListener(this._session, 'Page.frameAttached', this._onFrameAttached.bind(this)),
Expand Down Expand Up @@ -122,6 +123,13 @@ export class FFPage implements PageDelegate {
context.frame._contextDestroyed(context as dom.FrameExecutionContext);
}

private _removeContextsForFrame(frame: frames.Frame) {
for (const [contextId, context] of this._contextIdToContext) {
if (context.frame === frame)
this._contextIdToContext.delete(contextId);
}
}

_onNavigationStarted() {
}

Expand Down
21 changes: 14 additions & 7 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class WKPage implements PageDelegate {
this._page = new Page(this, browserContext);
this._workers = new WKWorkers(this._page);
this._session = undefined as any as WKSession;
this._page.on(Events.Page.FrameDetached, frame => this._removeContextsForFrame(frame, false));
}

private async _initializePageProxySession() {
Expand Down Expand Up @@ -248,13 +249,8 @@ export class WKPage implements PageDelegate {

private _onFrameNavigated(framePayload: Protocol.Page.Frame, initial: boolean) {
const frame = this._page._frameManager.frame(framePayload.id);
for (const [contextId, context] of this._contextIdToContext) {
if (context.frame === frame) {
(context._delegate as WKExecutionContext)._dispose();
this._contextIdToContext.delete(contextId);
frame._contextDestroyed(context);
}
}
assert(frame);
this._removeContextsForFrame(frame!, true);
if (!framePayload.parentId)
this._workers.clear();
this._page._frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url, framePayload.name || '', framePayload.loaderId, initial);
Expand All @@ -268,6 +264,17 @@ export class WKPage implements PageDelegate {
this._page._frameManager.frameDetached(frameId);
}

private _removeContextsForFrame(frame: frames.Frame, notifyFrame: boolean) {
for (const [contextId, context] of this._contextIdToContext) {
if (context.frame === frame) {
(context._delegate as WKExecutionContext)._dispose();
this._contextIdToContext.delete(contextId);
if (notifyFrame)
frame._contextDestroyed(context);
}
}
}

private _onExecutionContextCreated(contextPayload : Protocol.Runtime.ExecutionContextDescription) {
if (this._contextIdToContext.has(contextPayload.id))
return;
Expand Down
14 changes: 14 additions & 0 deletions test/evaluation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
expect(await page.frames()[0].evaluate(() => document.body.textContent.trim())).toBe('');
expect(await page.frames()[1].evaluate(() => document.body.textContent.trim())).toBe(`Hi, I'm frame`);
});
it('should dispose context on navigation', async({page, server}) => {
await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
expect(page._delegate._contextIdToContext.size).toBe(4);
await page.goto(server.EMPTY_PAGE);
expect(page._delegate._contextIdToContext.size).toBe(2);
});
it('should dispose context on cross-origin navigation', async({page, server}) => {
await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
expect(page._delegate._contextIdToContext.size).toBe(4);
await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(page._delegate._contextIdToContext.size).toBe(2);
});
it('should execute after cross-site navigation', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const mainFrame = page.mainFrame();
Expand Down