fix(Browser): wait for the page to close in the browser in page.close (#2064)
Fixes #1491
This commit is contained in:
parent
85081805ea
commit
d75fdb7098
@ -81,6 +81,7 @@ class Browser extends EventEmitter {
|
||||
const target = this._targets.get(event.targetId);
|
||||
target._initializedCallback(false);
|
||||
this._targets.delete(event.targetId);
|
||||
target._closedCallback();
|
||||
if (await target._initializedPromise)
|
||||
this.emit(Browser.Events.TargetDestroyed, target);
|
||||
}
|
||||
@ -198,6 +199,7 @@ class Target {
|
||||
/** @type {?Promise<!Page>} */
|
||||
this._pagePromise = null;
|
||||
this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill);
|
||||
this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);
|
||||
this._isInitialized = this._targetInfo.type !== 'page' || this._targetInfo.url !== '';
|
||||
if (this._isInitialized)
|
||||
this._initializedCallback(true);
|
||||
|
@ -798,7 +798,8 @@ class Page extends EventEmitter {
|
||||
|
||||
async close() {
|
||||
console.assert(!!this._client._connection, 'Protocol error: Connection closed. Most likely the page has been closed.');
|
||||
await this._client._connection.send('Target.closeTarget', {targetId: this._target._targetId});
|
||||
await this._client._connection.send('Target.closeTarget', { targetId: this._target._targetId });
|
||||
await this._target._isClosedPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,6 +390,12 @@ describe('Page', function() {
|
||||
await neverResolves.catch(e => error = e);
|
||||
expect(error.message).toContain('Protocol error');
|
||||
});
|
||||
it('should not be visible in browser.pages', async({browser}) => {
|
||||
const newPage = await browser.newPage();
|
||||
expect(await browser.pages()).toContain(newPage);
|
||||
await newPage.close();
|
||||
expect(await browser.pages()).not.toContain(newPage);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.Events.error', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user