Rename 'remoteDebuggingURL' into 'browserWSEndpoint' (#272)
This commit is contained in:
parent
44c15220f9
commit
0a190ebec9
15
docs/api.md
15
docs/api.md
@ -11,8 +11,8 @@
|
|||||||
* [class: Browser](#class-browser)
|
* [class: Browser](#class-browser)
|
||||||
+ [browser.close()](#browserclose)
|
+ [browser.close()](#browserclose)
|
||||||
+ [browser.newPage()](#browsernewpage)
|
+ [browser.newPage()](#browsernewpage)
|
||||||
+ [browser.remoteDebuggingURL()](#browserremotedebuggingurl)
|
|
||||||
+ [browser.version()](#browserversion)
|
+ [browser.version()](#browserversion)
|
||||||
|
+ [browser.wsEndpoint()](#browserwsendpoint)
|
||||||
* [class: Page](#class-page)
|
* [class: Page](#class-page)
|
||||||
+ [event: 'console'](#event-console)
|
+ [event: 'console'](#event-console)
|
||||||
+ [event: 'dialog'](#event-dialog)
|
+ [event: 'dialog'](#event-dialog)
|
||||||
@ -143,7 +143,7 @@ puppeteer.launch().then(async browser => {
|
|||||||
|
|
||||||
#### puppeteer.connect(options)
|
#### puppeteer.connect(options)
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `remoteDebuggingURL` <[string]> a [remote debugging URL](#browserremotedebuggingurl) to connect to.
|
- `browserWSEndpoint` <[string]> a [browser websocket endpoint](#browserwsendpoint) to connect to.
|
||||||
- `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`.
|
- `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`.
|
||||||
- returns: <[Promise]<[Browser]>>
|
- returns: <[Promise]<[Browser]>>
|
||||||
|
|
||||||
@ -185,16 +185,17 @@ Closes browser with all the pages (if any were opened). The browser object itsel
|
|||||||
#### browser.newPage()
|
#### browser.newPage()
|
||||||
- returns: <[Promise]<[Page]>> Promise which resolves to a new [Page] object.
|
- returns: <[Promise]<[Page]>> Promise which resolves to a new [Page] object.
|
||||||
|
|
||||||
#### browser.remoteDebuggingURL()
|
|
||||||
- returns: <[string]> A URL for debugging this browser instance.
|
|
||||||
|
|
||||||
Remote debugging url is as an argument to the [puppeteer.connect](#puppeteerconnect).
|
|
||||||
|
|
||||||
#### browser.version()
|
#### browser.version()
|
||||||
- returns: <[Promise]<[string]>> For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`.
|
- returns: <[Promise]<[string]>> For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`.
|
||||||
|
|
||||||
> **NOTE** the format of browser.version() might change with future releases of Chromium.
|
> **NOTE** the format of browser.version() might change with future releases of Chromium.
|
||||||
|
|
||||||
|
#### browser.wsEndpoint()
|
||||||
|
- returns: <[string]> Browser websocket url.
|
||||||
|
|
||||||
|
Browser websocket endpoint which could be used as an argument to
|
||||||
|
[puppeteer.connect](#puppeteerconnect).
|
||||||
|
|
||||||
### class: Page
|
### class: Page
|
||||||
|
|
||||||
Page provides methods to interact with a single tab in Chromium. One [Browser] instance might have multiple [Page] instances.
|
Page provides methods to interact with a single tab in Chromium. One [Browser] instance might have multiple [Page] instances.
|
||||||
|
@ -33,7 +33,7 @@ class Browser {
|
|||||||
/**
|
/**
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
remoteDebuggingURL() {
|
wsEndpoint() {
|
||||||
return this._connection.url();
|
return this._connection.url();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,17 +87,17 @@ class Launcher {
|
|||||||
removeRecursive(userDataDir);
|
removeRecursive(userDataDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
let remoteDebuggingURL = await waitForRemoteDebuggingURL(chromeProcess);
|
let browserWSEndpoint = await waitForWSEndpoint(chromeProcess);
|
||||||
if (terminated)
|
if (terminated)
|
||||||
throw new Error('Failed to launch chrome! ' + stderr);
|
throw new Error('Failed to launch chrome! ' + stderr);
|
||||||
// Failed to connect to browser.
|
// Failed to connect to browser.
|
||||||
if (!remoteDebuggingURL) {
|
if (!browserWSEndpoint) {
|
||||||
chromeProcess.kill();
|
chromeProcess.kill();
|
||||||
throw new Error('Failed to connect to chrome!');
|
throw new Error('Failed to connect to chrome!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectionDelay = options.slowMo || 0;
|
let connectionDelay = options.slowMo || 0;
|
||||||
let connection = await Connection.create(remoteDebuggingURL, connectionDelay);
|
let connection = await Connection.create(browserWSEndpoint, connectionDelay);
|
||||||
return new Browser(connection, !!options.ignoreHTTPSErrors, () => chromeProcess.kill());
|
return new Browser(connection, !!options.ignoreHTTPSErrors, () => chromeProcess.kill());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ class Launcher {
|
|||||||
* @param {string} options
|
* @param {string} options
|
||||||
* @return {!Promise<!Browser>}
|
* @return {!Promise<!Browser>}
|
||||||
*/
|
*/
|
||||||
static async connect({remoteDebuggingURL, ignoreHTTPSErrors = false}) {
|
static async connect({browserWSEndpoint, ignoreHTTPSErrors = false}) {
|
||||||
let connection = await Connection.create(remoteDebuggingURL);
|
let connection = await Connection.create(browserWSEndpoint);
|
||||||
return new Browser(connection, !!ignoreHTTPSErrors);
|
return new Browser(connection, !!ignoreHTTPSErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ class Launcher {
|
|||||||
* @param {!ChildProcess} chromeProcess
|
* @param {!ChildProcess} chromeProcess
|
||||||
* @return {!Promise<string>}
|
* @return {!Promise<string>}
|
||||||
*/
|
*/
|
||||||
function waitForRemoteDebuggingURL(chromeProcess) {
|
function waitForWSEndpoint(chromeProcess) {
|
||||||
return new Promise(fulfill => {
|
return new Promise(fulfill => {
|
||||||
const rl = readline.createInterface({ input: chromeProcess.stderr });
|
const rl = readline.createInterface({ input: chromeProcess.stderr });
|
||||||
rl.on('line', onLine);
|
rl.on('line', onLine);
|
||||||
|
@ -107,7 +107,7 @@ describe('Browser', function() {
|
|||||||
it('Puppeteer.connect', SX(async function() {
|
it('Puppeteer.connect', SX(async function() {
|
||||||
let originalBrowser = await puppeteer.launch(defaultBrowserOptions);
|
let originalBrowser = await puppeteer.launch(defaultBrowserOptions);
|
||||||
let browser = await puppeteer.connect({
|
let browser = await puppeteer.connect({
|
||||||
remoteDebuggingURL: originalBrowser.remoteDebuggingURL()
|
browserWSEndpoint: originalBrowser.wsEndpoint()
|
||||||
});
|
});
|
||||||
let page = await browser.newPage();
|
let page = await browser.newPage();
|
||||||
expect(await page.evaluate(() => 7 * 8)).toBe(56);
|
expect(await page.evaluate(() => 7 * 8)).toBe(56);
|
||||||
|
Loading…
Reference in New Issue
Block a user