parent
b522ecaa65
commit
32f4c173c8
@ -97,6 +97,7 @@
|
||||
* [page.goForward(options)](#pagegoforwardoptions)
|
||||
* [page.goto(url, options)](#pagegotourl-options)
|
||||
* [page.hover(selector)](#pagehoverselector)
|
||||
* [page.isClosed()](#pageisclosed)
|
||||
* [page.keyboard](#pagekeyboard)
|
||||
* [page.mainFrame()](#pagemainframe)
|
||||
* [page.metrics()](#pagemetrics)
|
||||
@ -1180,6 +1181,12 @@ If there's no element matching `selector`, the method throws an error.
|
||||
|
||||
Shortcut for [page.mainFrame().hover(selector)](#framehoverselector).
|
||||
|
||||
#### page.isClosed()
|
||||
|
||||
- returns: boolean
|
||||
|
||||
Indicates that the page has been closed.
|
||||
|
||||
#### page.keyboard
|
||||
|
||||
- returns: <[Keyboard]>
|
||||
|
13
lib/Page.js
13
lib/Page.js
@ -72,6 +72,7 @@ class Page extends EventEmitter {
|
||||
*/
|
||||
constructor(client, target, frameTree, ignoreHTTPSErrors, screenshotTaskQueue) {
|
||||
super();
|
||||
this._closed = false;
|
||||
this._client = client;
|
||||
this._target = target;
|
||||
this._keyboard = new Keyboard(client);
|
||||
@ -131,7 +132,10 @@ class Page extends EventEmitter {
|
||||
client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
||||
client.on('Performance.metrics', event => this._emitMetrics(event));
|
||||
client.on('Log.entryAdded', event => this._onLogEntryAdded(this._client, event));
|
||||
this._target._isClosedPromise.then(() => this.emit(Page.Events.Close));
|
||||
this._target._isClosedPromise.then(() => {
|
||||
this.emit(Page.Events.Close);
|
||||
this._closed = true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -876,6 +880,13 @@ class Page extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
isClosed() {
|
||||
return this._closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Mouse}
|
||||
*/
|
||||
|
@ -54,6 +54,12 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
|
||||
dialog.accept();
|
||||
await waitEvent(newPage, 'close');
|
||||
});
|
||||
it('should set the page close state', async({ browser }) => {
|
||||
const newPage = await browser.newPage();
|
||||
expect(newPage.isClosed()).toBe(false);
|
||||
await newPage.close();
|
||||
expect(newPage.isClosed()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.Events.error', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user