diff --git a/lib/Browser.js b/lib/Browser.js index b56cc9440f6..438c6211cea 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const { helper } = require('./helper'); +const { helper, assert } = require('./helper'); const Target = require('./Target'); const EventEmitter = require('events'); const TaskQueue = require('./TaskQueue'); @@ -108,7 +108,7 @@ class Browser extends EventEmitter { const context = (browserContextId && this._contexts.has(browserContextId)) ? this._contexts.get(browserContextId) : this._defaultContext; const target = new Target(targetInfo, context, () => this._connection.createSession(targetInfo.targetId), this._ignoreHTTPSErrors, this._setDefaultViewport, this._screenshotTaskQueue); - console.assert(!this._targets.has(event.targetInfo.targetId), 'Target should not exist before targetCreated'); + assert(!this._targets.has(event.targetInfo.targetId), 'Target should not exist before targetCreated'); this._targets.set(event.targetInfo.targetId, target); if (await target._initializedPromise) { @@ -136,7 +136,7 @@ class Browser extends EventEmitter { */ _targetInfoChanged(event) { const target = this._targets.get(event.targetInfo.targetId); - console.assert(target, 'target should exist before targetInfoChanged'); + assert(target, 'target should exist before targetInfoChanged'); const previousURL = target.url(); const wasInitialized = target._isInitialized; target._targetInfoChanged(event.targetInfo); @@ -167,7 +167,7 @@ class Browser extends EventEmitter { async _createPageInContext(contextId) { const {targetId} = await this._connection.send('Target.createTarget', {url: 'about:blank', browserContextId: contextId || undefined}); const target = await this._targets.get(targetId); - console.assert(await target._initializedPromise, 'Failed to create target for page'); + assert(await target._initializedPromise, 'Failed to create target for page'); const page = await target.page(); return page; } @@ -268,7 +268,7 @@ class BrowserContext extends EventEmitter { } async close() { - console.assert(this._id, 'Non-incognito profiles cannot be closed!'); + assert(this._id, 'Non-incognito profiles cannot be closed!'); await this._browser._disposeContext(this._id); } } diff --git a/lib/BrowserFetcher.js b/lib/BrowserFetcher.js index a967c1fd93e..0eb5cc9474b 100644 --- a/lib/BrowserFetcher.js +++ b/lib/BrowserFetcher.js @@ -20,7 +20,7 @@ const path = require('path'); const extract = require('extract-zip'); const util = require('util'); const URL = require('url'); -const {helper} = require('./helper'); +const {helper, assert} = require('./helper'); const removeRecursive = require('rimraf'); // @ts-ignore const ProxyAgent = require('https-proxy-agent'); @@ -63,10 +63,10 @@ class BrowserFetcher { this._platform = 'linux'; else if (platform === 'win32') this._platform = os.arch() === 'x64' ? 'win64' : 'win32'; - console.assert(this._platform, 'Unsupported platform: ' + os.platform()); + assert(this._platform, 'Unsupported platform: ' + os.platform()); } const supportedPlatforms = ['mac', 'linux', 'win32', 'win64']; - console.assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform); + assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform); } /** @@ -138,7 +138,7 @@ class BrowserFetcher { */ async remove(revision) { const folderPath = this._getFolderPath(revision); - console.assert(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`); + assert(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`); await new Promise(fulfill => removeRecursive(folderPath, fulfill)); } diff --git a/lib/Connection.js b/lib/Connection.js index f4b283ea23e..307f0675d37 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const {helper} = require('./helper'); +const {helper, assert} = require('./helper'); const debugProtocol = require('debug')('puppeteer:protocol'); const debugSession = require('debug')('puppeteer:session'); @@ -228,7 +228,7 @@ class CDPSession extends EventEmitter { this._sessions.delete(object.params.sessionId); } } - console.assert(!object.id); + assert(!object.id); this.emit(object.method, object.params); } } diff --git a/lib/Coverage.js b/lib/Coverage.js index 7fc20e495e9..288e0e51b43 100644 --- a/lib/Coverage.js +++ b/lib/Coverage.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const {helper, debugError} = require('./helper'); +const {helper, debugError, assert} = require('./helper'); /** * @typedef {Object} CoverageEntry @@ -81,7 +81,7 @@ class JSCoverage { * @param {!Object} options */ async start(options = {}) { - console.assert(!this._enabled, 'JSCoverage is already enabled'); + assert(!this._enabled, 'JSCoverage is already enabled'); this._resetOnNavigation = options.resetOnNavigation === undefined ? true : !!options.resetOnNavigation; this._enabled = true; this._scriptURLs.clear(); @@ -126,7 +126,7 @@ class JSCoverage { * @return {!Promise>} */ async stop() { - console.assert(this._enabled, 'JSCoverage is not enabled'); + assert(this._enabled, 'JSCoverage is not enabled'); this._enabled = false; const [profileResponse] = await Promise.all([ this._client.send('Profiler.takePreciseCoverage'), @@ -169,7 +169,7 @@ class CSSCoverage { * @param {!Object} options */ async start(options = {}) { - console.assert(!this._enabled, 'CSSCoverage is already enabled'); + assert(!this._enabled, 'CSSCoverage is already enabled'); this._resetOnNavigation = options.resetOnNavigation === undefined ? true : !!options.resetOnNavigation; this._enabled = true; this._stylesheetURLs.clear(); @@ -214,7 +214,7 @@ class CSSCoverage { * @return {!Promise>} */ async stop() { - console.assert(this._enabled, 'CSSCoverage is not enabled'); + assert(this._enabled, 'CSSCoverage is not enabled'); this._enabled = false; const [ruleTrackingResponse] = await Promise.all([ this._client.send('CSS.stopRuleUsageTracking'), diff --git a/lib/Dialog.js b/lib/Dialog.js index 78a071eab4c..23335d57f8d 100644 --- a/lib/Dialog.js +++ b/lib/Dialog.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const {helper} = require('./helper'); +const {helper, assert} = require('./helper'); class Dialog { /** @@ -56,7 +56,7 @@ class Dialog { * @param {string=} promptText */ async accept(promptText) { - console.assert(!this._handled, 'Cannot accept dialog which is already handled!'); + assert(!this._handled, 'Cannot accept dialog which is already handled!'); this._handled = true; await this._client.send('Page.handleJavaScriptDialog', { accept: true, @@ -65,7 +65,7 @@ class Dialog { } async dismiss() { - console.assert(!this._handled, 'Cannot dismiss dialog which is already handled!'); + assert(!this._handled, 'Cannot dismiss dialog which is already handled!'); this._handled = true; await this._client.send('Page.handleJavaScriptDialog', { accept: false diff --git a/lib/ExecutionContext.js b/lib/ExecutionContext.js index 1f3a2549796..3f50809b90e 100644 --- a/lib/ExecutionContext.js +++ b/lib/ExecutionContext.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const {helper} = require('./helper'); +const {helper, assert} = require('./helper'); class ExecutionContext { /** @@ -123,8 +123,8 @@ class ExecutionContext { * @return {!Promise} */ async queryObjects(prototypeHandle) { - console.assert(!prototypeHandle._disposed, 'Prototype JSHandle is disposed!'); - console.assert(prototypeHandle._remoteObject.objectId, 'Prototype JSHandle must not be referencing primitive value'); + assert(!prototypeHandle._disposed, 'Prototype JSHandle is disposed!'); + assert(prototypeHandle._remoteObject.objectId, 'Prototype JSHandle must not be referencing primitive value'); const response = await this._client.send('Runtime.queryObjects', { prototypeObjectId: prototypeHandle._remoteObject.objectId }); diff --git a/lib/FrameManager.js b/lib/FrameManager.js index ea0758eda5a..d24b0958c2e 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -16,7 +16,7 @@ const fs = require('fs'); const EventEmitter = require('events'); -const {helper} = require('./helper'); +const {helper, assert} = require('./helper'); const {ExecutionContext, JSHandle} = require('./ExecutionContext'); const ElementHandle = require('./ElementHandle'); @@ -116,7 +116,7 @@ class FrameManager extends EventEmitter { _onFrameAttached(frameId, parentFrameId) { if (this._frames.has(frameId)) return; - console.assert(parentFrameId); + assert(parentFrameId); const parentFrame = this._frames.get(parentFrameId); const frame = new Frame(this._client, this._page, parentFrame, frameId); this._frames.set(frame._id, frame); @@ -129,7 +129,7 @@ class FrameManager extends EventEmitter { _onFrameNavigated(framePayload) { const isMainFrame = !framePayload.parentId; let frame = isMainFrame ? this._mainFrame : this._frames.get(framePayload.id); - console.assert(isMainFrame || frame, 'We either navigate top level or have old version of the navigated frame'); + assert(isMainFrame || frame, 'We either navigate top level or have old version of the navigated frame'); // Detach all child frames first. if (frame) { @@ -220,7 +220,7 @@ class FrameManager extends EventEmitter { */ createJSHandle(contextId, remoteObject) { const context = this._contextIdToContext.get(contextId); - console.assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId); + assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId); if (remoteObject.subtype === 'node') return new ElementHandle(context, this._client, remoteObject, this._page, this); return new JSHandle(context, this._client, remoteObject); @@ -588,7 +588,7 @@ class Frame { */ async click(selector, options = {}) { const handle = await this.$(selector); - console.assert(handle, 'No node found for selector: ' + selector); + assert(handle, 'No node found for selector: ' + selector); await handle.click(options); await handle.dispose(); } @@ -598,7 +598,7 @@ class Frame { */ async focus(selector) { const handle = await this.$(selector); - console.assert(handle, 'No node found for selector: ' + selector); + assert(handle, 'No node found for selector: ' + selector); await handle.focus(); await handle.dispose(); } @@ -608,7 +608,7 @@ class Frame { */ async hover(selector) { const handle = await this.$(selector); - console.assert(handle, 'No node found for selector: ' + selector); + assert(handle, 'No node found for selector: ' + selector); await handle.hover(); await handle.dispose(); } @@ -620,7 +620,7 @@ class Frame { */ select(selector, ...values){ for (const value of values) - console.assert(helper.isString(value), 'Values must be strings. Found value "' + value + '" of type "' + (typeof value) + '"'); + assert(helper.isString(value), 'Values must be strings. Found value "' + value + '" of type "' + (typeof value) + '"'); return this.$eval(selector, (element, values) => { if (element.nodeName.toLowerCase() !== 'select') throw new Error('Element is not a