From 4269f6a1bb0c2d1cc27a9ed1132017669c33a259 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sat, 12 Aug 2017 22:04:39 -0700 Subject: [PATCH] Roll chromium to r493985 (#251) This patch: - rolls chromium to r493985 - migrates Browser.version() puppeteer method to use newly added Browser.getVersion() protocol method References #227 --- lib/Browser.js | 4 ++-- lib/Connection.js | 53 ----------------------------------------------- package.json | 2 +- 3 files changed, 3 insertions(+), 56 deletions(-) diff --git a/lib/Browser.js b/lib/Browser.js index 72e5a396..a63173ef 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -103,8 +103,8 @@ class Browser { */ async version() { await this._ensureChromeIsRunning(); - let version = await Connection.version(this._remoteDebuggingPort); - return version.Browser; + let version = await this._connection.send('Browser.getVersion'); + return version.product; } /** diff --git a/lib/Connection.js b/lib/Connection.js index d41f6304..711cfd26 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -18,8 +18,6 @@ const debugSession = require('debug')('puppeteer:session'); const EventEmitter = require('events'); const WebSocket = require('ws'); -const http = require('http'); -const COMMAND_TIMEOUT = 10000; class Connection extends EventEmitter { /** @@ -129,14 +127,6 @@ class Connection extends EventEmitter { ws.on('error', reject); }); } - - /** - * @param {number} port - * @return {!Promise} - */ - static version(port) { - return runJsonCommand(port, 'version'); - } } class Session extends EventEmitter { @@ -217,47 +207,4 @@ class Session extends EventEmitter { } } -/** - * @param {number} port - * @param {string} command - * @return {!Promise} - */ -function runJsonCommand(port, command) { - let request = http.get({ - hostname: 'localhost', - port: port, - path: '/json/' + command - }, onResponse); - request.setTimeout(COMMAND_TIMEOUT, onTimeout); - let resolve, reject; - return new Promise((res, rej) => { resolve = res; reject = rej; }); - - function onResponse(response) { - let data = ''; - response.on('data', chunk => data += chunk); - response.on('end', () => { - if (response.statusCode !== 200) { - reject(new Error(`Protocol JSON API error (${command}), status: ${response.statusCode}`)); - return; - } - // In the case of 'close' & 'activate' Chromium returns a string rather than JSON: goo.gl/7v27xD - if (data === 'Target is closing' || data === 'Target activated') { - resolve({message: data}); - return; - } - try { - resolve(JSON.parse(data)); - } catch (e) { - reject(e); - } - }); - } - - function onTimeout() { - request.abort(); - // Reject on error with code specifically indicating timeout in connection setup. - reject(new Error('Timeout waiting for initial Debugger Protocol connection.')); - } -} - module.exports = Connection; diff --git a/package.json b/package.json index 9376a5ef..1e63146f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "ws": "^3.0.0" }, "puppeteer": { - "chromium_revision": "493673" + "chromium_revision": "493985" }, "devDependencies": { "commonmark": "^0.27.0",