mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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.createIncognitoBrowserContext()](#browsercreateincognitobrowsercontext)
|
||||||
* [browser.defaultBrowserContext()](#browserdefaultbrowsercontext)
|
* [browser.defaultBrowserContext()](#browserdefaultbrowsercontext)
|
||||||
* [browser.disconnect()](#browserdisconnect)
|
* [browser.disconnect()](#browserdisconnect)
|
||||||
|
* [browser.isConnected()](#browserisconnected)
|
||||||
* [browser.newPage()](#browsernewpage)
|
* [browser.newPage()](#browsernewpage)
|
||||||
* [browser.pages()](#browserpages)
|
* [browser.pages()](#browserpages)
|
||||||
* [browser.process()](#browserprocess)
|
* [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.
|
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()
|
#### browser.newPage()
|
||||||
- returns: <[Promise]<[Page]>>
|
- returns: <[Promise]<[Page]>>
|
||||||
|
|
||||||
|
@ -57,6 +57,13 @@ class Browser extends EventEmitter {
|
|||||||
this._connection.dispose();
|
this._connection.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
isConnected() {
|
||||||
|
return !this._connection._closed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {!BrowserContext}
|
* @return {!BrowserContext}
|
||||||
*/
|
*/
|
||||||
|
@ -260,6 +260,13 @@ class Browser extends EventEmitter {
|
|||||||
this._connection.dispose();
|
this._connection.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
isConnected() {
|
||||||
|
return !this._connection._closed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {!Promise<!Object>}
|
* @return {!Promise<!Object>}
|
||||||
*/
|
*/
|
||||||
|
@ -60,4 +60,14 @@ module.exports.addTests = function({testRunner, expect, headless, puppeteer, CHR
|
|||||||
await remoteBrowser.disconnect();
|
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