Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(page): navigating 11 pages simultaneously should not throw warning #3560

Merged
merged 1 commit into from
Nov 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class CDPSession extends EventEmitter {
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): Target closed.`));
this._callbacks.clear();
this._connection = null;
this.emit(CDPSession.Events.Disconnected);
}

/**
Expand All @@ -240,6 +241,11 @@ class CDPSession extends EventEmitter {
return session;
}
}

CDPSession.Events = {
Disconnected: Symbol('CDPSession.Events.Disconnected'),
};

helper.tracePublicAPI(CDPSession);

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/FrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {helper, assert} = require('./helper');
const {ExecutionContext} = require('./ExecutionContext');
const {TimeoutError} = require('./Errors');
const {NetworkManager} = require('./NetworkManager');
const {Connection} = require('./Connection');
const {CDPSession} = require('./Connection');

const readFileAsync = helper.promisify(fs.readFile);

Expand Down Expand Up @@ -1162,7 +1162,7 @@ class NavigatorWatcher {
this._navigationRequest = null;
this._hasSameDocumentNavigation = false;
this._eventListeners = [
helper.addEventListener(Connection.fromSession(client), Connection.Events.Disconnected, () => this._terminate(new Error('Navigation failed because browser has disconnected!'))),
helper.addEventListener(client, CDPSession.Events.Disconnected, () => this._terminate(new Error('Navigation failed because browser has disconnected!'))),
helper.addEventListener(this._frameManager, FrameManager.Events.LifecycleEvent, this._checkLifecycleComplete.bind(this)),
helper.addEventListener(this._frameManager, FrameManager.Events.FrameNavigatedWithinDocument, this._navigatedWithinDocument.bind(this)),
helper.addEventListener(this._frameManager, FrameManager.Events.FrameDetached, this._onFrameDetached.bind(this)),
Expand Down
12 changes: 12 additions & 0 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ module.exports.addTests = function({testRunner, expect, headless}) {
process.removeListener('warning', warningHandler);
expect(warning).toBe(null);
});
it('should not leak listeners during navigation of 11 pages', async({page, context, server}) => {
let warning = null;
const warningHandler = w => warning = w;
process.on('warning', warningHandler);
await Promise.all([...Array(20)].map(async() => {
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.close();
}));
process.removeListener('warning', warningHandler);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks like it might fail in parallel if some other test creates a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:'(

expect(warning).toBe(null);
});
it('should navigate to dataURL and fire dataURL requests', async({page, server}) => {
const requests = [];
page.on('request', request => requests.push(request));
Expand Down