diff --git a/lib/Browser.js b/lib/Browser.js index 9812664c53d..6f7d569ea49 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -32,8 +32,8 @@ var DEFAULT_ARGS = [ class Browser { /** - * @param {(!Object|undefined)} options - */ + * @param {(!Object|undefined)} options + */ constructor(options) { options = options || {}; ++browserId; diff --git a/lib/Connection.js b/lib/Connection.js index 7795e5b616e..25f924598da 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -21,10 +21,10 @@ const COMMAND_TIMEOUT = 10000; class Connection extends EventEmitter { /** - * @param {number} port - * @param {string} pageId - * @param {!WebSocket} ws - */ + * @param {number} port + * @param {string} pageId + * @param {!WebSocket} ws + */ constructor(port, pageId, ws) { super(); this._port = port; @@ -39,10 +39,10 @@ class Connection extends EventEmitter { } /** - * @param {string} method - * @param {(!Object|undefined)} params - * @return {!Promise} - */ + * @param {string} method + * @param {(!Object|undefined)} params + * @return {!Promise} + */ send(method, params = {}) { var id = ++this._lastId; var message = JSON.stringify({id, method, params}); @@ -53,8 +53,8 @@ class Connection extends EventEmitter { } /** - * @param {string} message - */ + * @param {string} message + */ _onMessage(message) { var object = JSON.parse(message); if (object.id && this._callbacks.has(object.id)) { @@ -76,16 +76,16 @@ class Connection extends EventEmitter { } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async dispose() { await runJsonCommand(this._port, `close/${this._pageId}`); } /** - * @param {number} port - * @return {!Promise} - */ + * @param {number} port + * @return {!Promise} + */ static async create(port) { var newTab = await runJsonCommand(port, 'new'); var url = newTab.webSocketDebuggerUrl; @@ -98,9 +98,9 @@ class Connection extends EventEmitter { } /** - * @param {number} port - * @return {!Promise} - */ + * @param {number} port + * @return {!Promise} + */ static version(port) { return runJsonCommand(port, 'version'); } diff --git a/lib/Dialog.js b/lib/Dialog.js index 8f01e2ded7a..af2cbf34d15 100644 --- a/lib/Dialog.js +++ b/lib/Dialog.js @@ -16,10 +16,10 @@ class Dialog { /** - * @param {!Connection} client - * @param {!Dialog.Type} type - * @param {string} message - */ + * @param {!Connection} client + * @param {!Dialog.Type} type + * @param {string} message + */ constructor(client, type, message) { this._client = client; this.type = type; @@ -28,16 +28,16 @@ class Dialog { } /** - * @return {string} - */ + * @return {string} + */ message() { return this._message; } /** - * @param {string=} promptText - * @return {!Promise} - */ + * @param {string=} promptText + * @return {!Promise} + */ async accept(promptText) { console.assert(!this._handled, 'Cannot accept dialog which is already handled!'); this._handled = true; @@ -48,8 +48,8 @@ class Dialog { } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async dismiss() { console.assert(!this._handled, 'Cannot dismiss dialog which is already handled!'); this._handled = true; diff --git a/lib/FrameManager.js b/lib/FrameManager.js index 175c632c002..8763229aa4a 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -18,18 +18,18 @@ var EventEmitter = require('events'); class FrameManager extends EventEmitter { /** - * @param {!Connection} client - * @return {!FrameManager} - */ + * @param {!Connection} client + * @return {!FrameManager} + */ static async create(client) { var mainFramePayload = await client.send('Page.getResourceTree'); return new FrameManager(client, mainFramePayload.frameTree); } /** - * @param {!Connection} client - * @param {!Object} frameTree - */ + * @param {!Connection} client + * @param {!Object} frameTree + */ constructor(client, frameTree) { super(); this._client = client; @@ -43,24 +43,24 @@ class FrameManager extends EventEmitter { } /** - * @return {!Frame} - */ + * @return {!Frame} + */ mainFrame() { return this._mainFrame; } /** - * @return {!Array} - */ + * @return {!Array} + */ frames() { return Array.from(this._frames.values()); } /** - * @param {string} frameId - * @param {?string} parentFrameId - * @return {?Frame} - */ + * @param {string} frameId + * @param {?string} parentFrameId + * @return {?Frame} + */ _frameAttached(frameId, parentFrameId) { if (this._frames.has(frameId)) return; @@ -77,8 +77,8 @@ class FrameManager extends EventEmitter { } /** - * @param {!Object} framePayload - */ + * @param {!Object} framePayload + */ _frameNavigated(framePayload) { var frame = this._frames.get(framePayload.id); if (!frame) { @@ -90,8 +90,8 @@ class FrameManager extends EventEmitter { } /** - * @param {string} frameId - */ + * @param {string} frameId + */ _frameDetached(frameId) { var frame = this._frames.get(frameId); if (frame) @@ -99,10 +99,10 @@ class FrameManager extends EventEmitter { } /** - * @param {!Frame} frame - * @param {string} newFrameId - * @param {?Object} newFramePayload - */ + * @param {!Frame} frame + * @param {string} newFrameId + * @param {?Object} newFramePayload + */ _navigateFrame(frame, newFrameId, newFramePayload) { // Detach all child frames first. for (var child of frame.childFrames()) @@ -115,10 +115,10 @@ class FrameManager extends EventEmitter { } /** - * @param {?Frame} parentFrame - * @param {!Object} frameTreePayload - * @return {!Frame} - */ + * @param {?Frame} parentFrame + * @param {!Object} frameTreePayload + * @return {!Frame} + */ _addFramesRecursively(parentFrame, frameTreePayload) { var framePayload = frameTreePayload.frame; var frame = new Frame(parentFrame, framePayload.id, framePayload); @@ -130,8 +130,8 @@ class FrameManager extends EventEmitter { } /** - * @param {!Frame} frame - */ + * @param {!Frame} frame + */ _removeFramesRecursively(frame) { for (var child of frame.childFrames()) this._removeFramesRecursively(child); @@ -153,10 +153,10 @@ FrameManager.Events = { */ class Frame { /** - * @param {?Frame} parentFrame - * @param {string} frameId - * @param {?Object} payload - */ + * @param {?Frame} parentFrame + * @param {string} frameId + * @param {?Object} payload + */ constructor(parentFrame, frameId, payload) { this._parentFrame = parentFrame; this._url = ''; @@ -170,57 +170,57 @@ class Frame { } /** - * @return {string} - */ + * @return {string} + */ name() { return this._name || ''; } /** - * @return {string} - */ + * @return {string} + */ url() { return this._url; } /** - * @return {string} - */ + * @return {string} + */ securityOrigin() { return this._securityOrigin; } /** - * @return {?Frame} - */ + * @return {?Frame} + */ parentFrame() { return this._parentFrame; } /** - * @return {!Array.} - */ + * @return {!Array.} + */ childFrames() { return Array.from(this._childFrames); } /** - * @return {boolean} - */ + * @return {boolean} + */ isMainFrame() { return !this._detached && !this._parentFrame; } /** - * @return {boolean} - */ + * @return {boolean} + */ isDetached() { return this._detached; } /** - * @param {?Object} framePayload - */ + * @param {?Object} framePayload + */ _adoptPayload(framePayload) { framePayload = framePayload || { name: '', diff --git a/lib/Navigator.js b/lib/Navigator.js index 188c145d65f..38dda16ebf6 100644 --- a/lib/Navigator.js +++ b/lib/Navigator.js @@ -16,9 +16,9 @@ class Navigator { /** - * @param {!Connection} client - * @param {!Object=} options - */ + * @param {!Connection} client + * @param {!Object=} options + */ constructor(client, options) { this._client = client; client.on('Network.requestWillBeSent', event => this._onRequestWillBeSent(event)); @@ -30,9 +30,9 @@ class Navigator { } /** - * @param {string} url - * @param {string=} referrer - */ + * @param {string} url + * @param {string=} referrer + */ async navigate(url, referrer) { this._navigationStartTime = Date.now(); this._watchdogTimer = setTimeout(this._completeNavigation.bind(this, true), this._maxTime); @@ -52,23 +52,23 @@ class Navigator { } /** - * @param {!Object} event - */ + * @param {!Object} event + */ _onRequestWillBeSent(event) { if (!event.redirectResponse) ++this._inflightRequests; } /** - * @param {!Object} event - */ + * @param {!Object} event + */ _onLoadingFinished(event) { this._onLoadingCompleted(event); } /** - * @param {!Object} event - */ + * @param {!Object} event + */ _onLoadingFailed(event) { this._onLoadingCompleted(event); } @@ -81,8 +81,8 @@ class Navigator { } /** - * @param {boolean} force - */ + * @param {boolean} force + */ _completeNavigation(force) { if (!this._navigationLoadCallback) return; diff --git a/lib/Page.js b/lib/Page.js index a9a5809a175..83d60cd004f 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -24,9 +24,9 @@ var FrameManager = require('./FrameManager'); class Page extends EventEmitter { /** - * @param {!Connection} client - * @return {!Promise} - */ + * @param {!Connection} client + * @return {!Promise} + */ static async create(client) { await Promise.all([ client.send('Network.enable', {}), @@ -44,10 +44,10 @@ class Page extends EventEmitter { } /** - * @param {!Connection} client - * @param {!FrameManager} frameManager - * @param {number} screenDPI - */ + * @param {!Connection} client + * @param {!FrameManager} frameManager + * @param {number} screenDPI + */ constructor(client, frameManager, screenDPI) { super(); this._client = client; @@ -75,45 +75,45 @@ class Page extends EventEmitter { } /** - * @return {!Frame} - */ + * @return {!Frame} + */ mainFrame() { return this._frameManager.mainFrame(); } /** - * @return {!Array} - */ + * @return {!Array} + */ frames() { return this._frameManager.frames(); } /** - * @param {?function(!Request)} interceptor - */ + * @param {?function(!Request)} interceptor + */ async setRequestInterceptor(interceptor) { this._requestInterceptor = interceptor; await this._client.send('Network.enableRequestInterception', {enabled: !!interceptor}); } /** - * @param {!Object} event - */ + * @param {!Object} event + */ _onRequestIntercepted(event) { var request = new Request(this._client, event.InterceptionId, event.request); this._requestInterceptor(request); } /** - * @param {string} url - * @return {!Promise} - */ + * @param {string} url + * @return {!Promise} + */ async addScriptTag(url) { return this.evaluate(addScriptTag, url); /** - * @param {string} url - */ + * @param {string} url + */ function addScriptTag(url) { var script = document.createElement('script'); script.src = url; @@ -124,9 +124,9 @@ class Page extends EventEmitter { } /** - * @param {string} filePath - * @return {!Promise} - */ + * @param {string} filePath + * @return {!Promise} + */ async injectFile(filePath) { var callback; var promise = new Promise(fulfill => callback = fulfill); @@ -136,9 +136,9 @@ class Page extends EventEmitter { } /** - * @param {string} name - * @param {function(?)} callback - */ + * @param {string} name + * @param {function(?)} callback + */ async setInPageCallback(name, callback) { if (this._inPageCallbacks[name]) throw new Error(`Failed to set in-page callback with name ${name}: window['${name}'] already exists!`); @@ -167,9 +167,9 @@ class Page extends EventEmitter { } /** - * @param {!Object} headers - * @return {!Promise} - */ + * @param {!Object} headers + * @return {!Promise} + */ async setExtraHTTPHeaders(headers) { this._extraHeaders = {}; // Note: header names are case-insensitive. @@ -179,31 +179,31 @@ class Page extends EventEmitter { } /** - * @return {!Object} - */ + * @return {!Object} + */ extraHTTPHeaders() { return Object.assign({}, this._extraHeaders); } /** - * @param {string} userAgent - * @return {!Promise} - */ + * @param {string} userAgent + * @return {!Promise} + */ async setUserAgentOverride(userAgent) { this._userAgent = userAgent; return this._client.send('Network.setUserAgentOverride', { userAgent }); } /** - * @return {string} - */ + * @return {string} + */ userAgentOverride() { return this._userAgent; } /** - * @param {!Object} exceptionDetails - */ + * @param {!Object} exceptionDetails + */ async _handleException(exceptionDetails) { var message = await this._getExceptionMessage(exceptionDetails); this.emit(Page.Events.Error, new Error(message)); @@ -242,16 +242,16 @@ class Page extends EventEmitter { } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async url() { return this.evaluate(() => window.location.href); } /** - * @param {string} html - * @return {!Promise} - */ + * @param {string} html + * @return {!Promise} + */ async setContent(html) { this.evaluate(() => { document.open(); @@ -261,18 +261,18 @@ class Page extends EventEmitter { } /** - * @param {string} html - * @param {!Object=} options - * @return {!Promise} - */ + * @param {string} html + * @param {!Object=} options + * @return {!Promise} + */ navigate(url, options) { return new Navigator(this._client, options).navigate(url, this._extraHeaders.referer); } /** - * @param {!{width: number, height: number}} size - * @return {!Promise} - */ + * @param {!{width: number, height: number}} size + * @return {!Promise} + */ async setViewportSize(size) { this._viewportSize = size; var width = size.width; @@ -295,17 +295,17 @@ class Page extends EventEmitter { } /** - * @return {!{width: number, height: number}} - */ + * @return {!{width: number, height: number}} + */ viewportSize() { return this._viewportSize; } /** - * @param {function()} fun - * @param {!Array<*>} args - * @return {!Promise<(!Object|undefined)>} - */ + * @param {function()} fun + * @param {!Array<*>} args + * @return {!Promise<(!Object|undefined)>} + */ async evaluate(fun, ...args) { var syncExpression = Page._evaluationString(fun, ...args); var expression = `Promise.resolve(${syncExpression})`; @@ -318,9 +318,9 @@ class Page extends EventEmitter { } /** - * @param {!Object} exceptionDetails - * @return {string} - */ + * @param {!Object} exceptionDetails + * @return {string} + */ async _getExceptionMessage(exceptionDetails) { var message = ''; var exception = exceptionDetails.exception; @@ -346,28 +346,28 @@ class Page extends EventEmitter { } /** - * @param {function()} fun - * @param {!Array<*>} args - * @return {!Promise} - */ + * @param {function()} fun + * @param {!Array<*>} args + * @return {!Promise} + */ async evaluateOnInitialized(fun, ...args) { var scriptSource = Page._evaluationString(fun, ...args); await this._client.send('Page.addScriptToEvaluateOnLoad', { scriptSource }); } /** - * @param {function()} fun - * @param {!Array<*>} args - * @return {string} - */ + * @param {function()} fun + * @param {!Array<*>} args + * @return {string} + */ static _evaluationString(fun, ...args) { return `(${fun})(${args.map(x => JSON.stringify(x)).join(',')})`; } /** - * @param {!Object=} options - * @return {!Promise} - */ + * @param {!Object=} options + * @return {!Promise} + */ async screenshot(options) { options = options || {}; var screenshotType = null; @@ -405,10 +405,10 @@ class Page extends EventEmitter { } /** - * @param {string} screenshotType - * @param {!Object=} options - * @return {!Promise} - */ + * @param {string} screenshotType + * @param {!Object=} options + * @return {!Promise} + */ async _screenshotTask(screenshotType, options) { if (options.clip) { await Promise.all([ @@ -454,10 +454,10 @@ class Page extends EventEmitter { } /** - * @param {string} filePath - * @param {!Object=} options - * @return {!Promise} - */ + * @param {string} filePath + * @param {!Object=} options + * @return {!Promise} + */ async printToPDF(filePath, options) { options = options || {}; @@ -503,22 +503,22 @@ class Page extends EventEmitter { } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async plainText() { return this.evaluate(() => document.body.innerText); } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async title() { return this.evaluate(() => document.title); } /** - * @return {!Promise} - */ + * @return {!Promise} + */ async close() { await this._client.dispose(); } diff --git a/lib/Request.js b/lib/Request.js index 6f663dbfeaf..e74fc828f77 100644 --- a/lib/Request.js +++ b/lib/Request.js @@ -16,10 +16,10 @@ class Request { /** - * @param {!Connection} client - * @param {string} interceptionId - * @param {!Object} payload - */ + * @param {!Connection} client + * @param {string} interceptionId + * @param {!Object} payload + */ constructor(client, interceptionId, payload) { this._client = client; this._interceptionId = interceptionId; @@ -36,44 +36,44 @@ class Request { } /** - * @return {string} - */ + * @return {string} + */ url() { return this._urlOverride || this._url; } /** - * @param {string} url - */ + * @param {string} url + */ setUrl(url) { this._urlOverride = url; } /** - * @return {string} - */ + * @return {string} + */ method() { return this._methodOverride || this._method; } /** - * @param {string} method - */ + * @param {string} method + */ setMethod(method) { this._methodOverride = method; } /** - * @return {!Object} - */ + * @return {!Object} + */ headers() { return Object.assign({}, this._headersOverride || this._headers); } /** - * @param {string} key - * @param {string} value - */ + * @param {string} key + * @param {string} value + */ setHeader(key, value) { if (!this._headersOverride) this._headersOverride = Object.assign({}, this._headers); @@ -81,15 +81,15 @@ class Request { } /** - * @return {(string|undefined)} - */ + * @return {(string|undefined)} + */ postData() { return this._postDataOverride || this._postData; } /** - * @return {(string|undefined)} - */ + * @return {(string|undefined)} + */ setPostData(data) { this._postDataOverride = data; } @@ -116,8 +116,8 @@ class Request { } /** - * @return {boolean} - */ + * @return {boolean} + */ handled() { return this._handled; } diff --git a/test/StaticServer.js b/test/StaticServer.js index 1b28a9eb92c..8cdf930c98c 100644 --- a/test/StaticServer.js +++ b/test/StaticServer.js @@ -22,9 +22,9 @@ var mime = require('mime'); class StaticServer { /** - * @param {string} dirPath - * @param {number} port - */ + * @param {string} dirPath + * @param {number} port + */ constructor(dirPath, port) { this._server = http.createServer(this._onRequest.bind(this)); this._server.listen(port); diff --git a/test/frame-utils.js b/test/frame-utils.js index efc14d8e55e..2dfc3105b94 100644 --- a/test/frame-utils.js +++ b/test/frame-utils.js @@ -1,10 +1,10 @@ var utils = module.exports = { /** - * @param {!Page} page - * @param {string} frameId - * @param {string} url - * @return {!Promise} - */ + * @param {!Page} page + * @param {string} frameId + * @param {string} url + * @return {!Promise} + */ attachFrame: async function(page, frameId, url) { await page.evaluate(attachFrame, frameId, url); @@ -18,10 +18,10 @@ var utils = module.exports = { }, /** - * @param {!Page} page - * @param {string} frameId - * @return {!Promise} - */ + * @param {!Page} page + * @param {string} frameId + * @return {!Promise} + */ detachFrame: async function(page, frameId) { await page.evaluate(detachFrame, frameId); @@ -32,11 +32,11 @@ var utils = module.exports = { }, /** - * @param {!Page} page - * @param {string} frameId - * @param {string} url - * @return {!Promise} - */ + * @param {!Page} page + * @param {string} frameId + * @param {string} url + * @return {!Promise} + */ navigateFrame: async function(page, frameId, url) { await page.evaluate(navigateFrame, frameId, url); @@ -48,10 +48,10 @@ var utils = module.exports = { }, /** - * @param {!Frame} frame - * @param {string=} indentation - * @return {string} - */ + * @param {!Frame} frame + * @param {string=} indentation + * @return {string} + */ dumpFrames: function(frame, indentation) { indentation = indentation || ''; var result = indentation + frame.url();