diff --git a/lib/Page.js b/lib/Page.js index abe1d428..5d94eecf 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -26,7 +26,7 @@ const {Keyboard, Mouse, Touchscreen} = require('./Input'); const Tracing = require('./Tracing'); const {helper, debugError, assert} = require('./helper'); const {Coverage} = require('./Coverage'); -const {Worker} = require('./Worker'); +const {Worker: PuppeteerWorker} = require('./Worker'); const {createJSHandle} = require('./JSHandle'); const {Accessibility} = require('./Accessibility'); const {TimeoutSettings} = require('./TimeoutSettings'); @@ -79,7 +79,7 @@ class Page extends EventEmitter { this._screenshotTaskQueue = screenshotTaskQueue; - /** @type {!Map} */ + /** @type {!Map} */ this._workers = new Map(); client.on('Target.attachedToTarget', event => { if (event.targetInfo.type !== 'worker') { @@ -90,7 +90,7 @@ class Page extends EventEmitter { return; } const session = Connection.fromSession(client).session(event.sessionId); - const worker = new Worker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this)); + const worker = new PuppeteerWorker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this)); this._workers.set(event.sessionId, worker); this.emit(Events.Page.WorkerCreated, worker); }); @@ -274,7 +274,7 @@ class Page extends EventEmitter { } /** - * @return {!Array} + * @return {!Array} */ workers() { return Array.from(this._workers.values()); diff --git a/lib/Target.js b/lib/Target.js index f8bbe6fe..3b3ae42a 100644 --- a/lib/Target.js +++ b/lib/Target.js @@ -16,7 +16,7 @@ const {Events} = require('./Events'); const {Page} = require('./Page'); -const {Worker} = require('./Worker'); +const {Worker: PuppeteerWorker} = require('./Worker'); class Target { /** @@ -37,7 +37,7 @@ class Target { this._screenshotTaskQueue = screenshotTaskQueue; /** @type {?Promise} */ this._pagePromise = null; - /** @type {?Promise} */ + /** @type {?Promise} */ this._workerPromise = null; this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill).then(async success => { if (!success) @@ -77,7 +77,7 @@ class Target { } /** - * @return {!Promise} + * @return {!Promise} */ async worker() { if (this._targetInfo.type !== 'service_worker' && this._targetInfo.type !== 'shared_worker') @@ -85,7 +85,7 @@ class Target { if (!this._workerPromise) { // TODO(einbinder): Make workers send their console logs. this._workerPromise = this._sessionFactory() - .then(client => new Worker(client, this._targetInfo.url, () => {} /* consoleAPICalled */, () => {} /* exceptionThrown */)); + .then(client => new PuppeteerWorker(client, this._targetInfo.url, () => {} /* consoleAPICalled */, () => {} /* exceptionThrown */)); } return this._workerPromise; } diff --git a/lib/WebSocketTransport.js b/lib/WebSocketTransport.js index 7bf5a0a9..ff951e15 100644 --- a/lib/WebSocketTransport.js +++ b/lib/WebSocketTransport.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const WebSocket = require('ws'); +const NodeWebSocket = require('ws'); /** * @implements {!Puppeteer.ConnectionTransport} @@ -25,17 +25,22 @@ class WebSocketTransport { */ static create(url) { return new Promise((resolve, reject) => { - const ws = new WebSocket(url, [], { + const ws = new NodeWebSocket(url, [], { perMessageDeflate: false, maxPayload: 256 * 1024 * 1024, // 256Mb }); + + /* error that WebSocket is not assignable to type WebSocket + * due to a misisng dispatchEvent() method which the ws library + * does not implement and we do not need + */ ws.addEventListener('open', () => resolve(new WebSocketTransport(ws))); ws.addEventListener('error', reject); }); } /** - * @param {!WebSocket} ws + * @param {!NodeWebSocket} ws */ constructor(ws) { this._ws = ws; diff --git a/package.json b/package.json index 578cdf5e..de264fde 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "pixelmatch": "^4.0.2", "pngjs": "^3.3.3", "text-diff": "^1.0.1", - "typescript": "3.5.3" + "typescript": "3.6.5" }, "browser": { "./lib/BrowserFetcher.js": false,