diff --git a/docs/api.md b/docs/api.md index 58292b7e..a928396a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -11,8 +11,8 @@ * [class: Browser](#class-browser) + [browser.close()](#browserclose) + [browser.newPage()](#browsernewpage) - + [browser.remoteDebuggingURL()](#browserremotedebuggingurl) + [browser.version()](#browserversion) + + [browser.wsEndpoint()](#browserwsendpoint) * [class: Page](#class-page) + [event: 'console'](#event-console) + [event: 'dialog'](#event-dialog) @@ -143,7 +143,7 @@ puppeteer.launch().then(async browser => { #### puppeteer.connect(options) - `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`. - returns: <[Promise]<[Browser]>> @@ -185,16 +185,17 @@ Closes browser with all the pages (if any were opened). The browser object itsel #### browser.newPage() - 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() - 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. +#### browser.wsEndpoint() +- returns: <[string]> Browser websocket url. + +Browser websocket endpoint which could be used as an argument to +[puppeteer.connect](#puppeteerconnect). + ### class: Page Page provides methods to interact with a single tab in Chromium. One [Browser] instance might have multiple [Page] instances. @@ -1240,4 +1241,4 @@ Contains the URL of the response. [selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector" [Tracing]: #class-tracing "Tracing" [ElementHandle]: #class-element "ElementHandle" -[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail" \ No newline at end of file +[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail" diff --git a/lib/Browser.js b/lib/Browser.js index b0b8fd7b..ffaa5b47 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -33,7 +33,7 @@ class Browser { /** * @return {string} */ - remoteDebuggingURL() { + wsEndpoint() { return this._connection.url(); } diff --git a/lib/Launcher.js b/lib/Launcher.js index 787a1d38..e991bd99 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -87,17 +87,17 @@ class Launcher { removeRecursive(userDataDir); }); - let remoteDebuggingURL = await waitForRemoteDebuggingURL(chromeProcess); + let browserWSEndpoint = await waitForWSEndpoint(chromeProcess); if (terminated) throw new Error('Failed to launch chrome! ' + stderr); // Failed to connect to browser. - if (!remoteDebuggingURL) { + if (!browserWSEndpoint) { chromeProcess.kill(); throw new Error('Failed to connect to chrome!'); } 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()); } @@ -105,8 +105,8 @@ class Launcher { * @param {string} options * @return {!Promise} */ - static async connect({remoteDebuggingURL, ignoreHTTPSErrors = false}) { - let connection = await Connection.create(remoteDebuggingURL); + static async connect({browserWSEndpoint, ignoreHTTPSErrors = false}) { + let connection = await Connection.create(browserWSEndpoint); return new Browser(connection, !!ignoreHTTPSErrors); } } @@ -115,7 +115,7 @@ class Launcher { * @param {!ChildProcess} chromeProcess * @return {!Promise} */ -function waitForRemoteDebuggingURL(chromeProcess) { +function waitForWSEndpoint(chromeProcess) { return new Promise(fulfill => { const rl = readline.createInterface({ input: chromeProcess.stderr }); rl.on('line', onLine); diff --git a/test/test.js b/test/test.js index a888279e..b0d29b66 100644 --- a/test/test.js +++ b/test/test.js @@ -107,7 +107,7 @@ describe('Browser', function() { it('Puppeteer.connect', SX(async function() { let originalBrowser = await puppeteer.launch(defaultBrowserOptions); let browser = await puppeteer.connect({ - remoteDebuggingURL: originalBrowser.remoteDebuggingURL() + browserWSEndpoint: originalBrowser.wsEndpoint() }); let page = await browser.newPage(); expect(await page.evaluate(() => 7 * 8)).toBe(56);