feat(browser): Add browser.isConnected() (#4403)
Add `browser.isConnected()` to the public api to be able to tell when the browser is connected fixes https://github.com/smooth-code/jest-puppeteer/pull/237#issuecomment-490260041
This commit is contained in:
parent
13f73b5b3a
commit
511dcf9d32
@ -48,6 +48,7 @@
|
||||
* [browser.createIncognitoBrowserContext()](#browsercreateincognitobrowsercontext)
|
||||
* [browser.defaultBrowserContext()](#browserdefaultbrowsercontext)
|
||||
* [browser.disconnect()](#browserdisconnect)
|
||||
* [browser.isConnected()](#browserisconnected)
|
||||
* [browser.newPage()](#browsernewpage)
|
||||
* [browser.pages()](#browserpages)
|
||||
* [browser.process()](#browserprocess)
|
||||
@ -700,6 +701,12 @@ Returns the default browser context. The default browser context can not be clos
|
||||
|
||||
Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling `disconnect`, the [Browser] object is considered disposed and cannot be used anymore.
|
||||
|
||||
#### browser.isConnected()
|
||||
|
||||
- returns: <[boolean]>
|
||||
|
||||
Indicates that the browser is connected.
|
||||
|
||||
#### browser.newPage()
|
||||
- returns: <[Promise]<[Page]>>
|
||||
|
||||
|
@ -57,6 +57,13 @@ class Browser extends EventEmitter {
|
||||
this._connection.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
isConnected() {
|
||||
return !this._connection._closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!BrowserContext}
|
||||
*/
|
||||
|
@ -260,6 +260,13 @@ class Browser extends EventEmitter {
|
||||
this._connection.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
isConnected() {
|
||||
return !this._connection._closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<!Object>}
|
||||
*/
|
||||
|
@ -60,4 +60,14 @@ module.exports.addTests = function({testRunner, expect, headless, puppeteer, CHR
|
||||
await remoteBrowser.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Browser.isConnected', () => {
|
||||
it('should set the browser connected state', async({browser}) => {
|
||||
const browserWSEndpoint = browser.wsEndpoint();
|
||||
const newBrowser = await puppeteer.connect({browserWSEndpoint});
|
||||
expect(newBrowser.isConnected()).toBe(true);
|
||||
await newBrowser.disconnect();
|
||||
expect(newBrowser.isConnected()).toBe(false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user