Driver

Driver

new Driver(connectionnon-null)

Source:
Parameters:
Name Type Description
connection Connection

Members

(private) _monitoredUrl

Used for monitoring url redirects during gotoURL.

Source:

(private) _networkStatusMonitor

Used for monitoring network status events during gotoURL.

Source:

Methods

(private) _beginNetworkStatusMonitoring(startingUrl) → (non-null) {Promise}

Set up listener for network quiet events and URL redirects. Passed in URL will be monitored for redirects, with the final loaded URL passed back in _endNetworkStatusMonitoring.

Source:
Parameters:
Name Type Description
startingUrl string
Returns:
Type:
Promise

(private) _endNetworkStatusMonitoring() → {string}

End network status listening. Returns the final, possibly redirected, loaded URL starting with the one passed into _endNetworkStatusMonitoring.

Source:
Returns:
Type:
string

_evaluateInContext(expression, contextId) → (non-null) {Promise.<*>}

Evaluate an expression in the given execution context; an undefined contextId implies the main page without isolation.

Source:
Parameters:
Name Type Description
expression string
contextId number | undefined
Returns:
Type:
Promise.<*>

_getOrCreateIsolatedContextId() → (non-null) {Promise.<number>}

Returns the cached isolated execution context ID or creates a new execution context for the main frame. The cached execution context is cleared on every gotoURL invocation, so a new one will always be created on the first call on a new page.

Source:
Returns:
Type:
Promise.<number>

(private) _shouldToggleDomain(domain, enable) → {boolean}

Debounce enabling or disabling domains to prevent driver users from stomping on each other. Maintains an internal count of the times a domain has been enabled. Returns false if the command would have no effect (domain is already enabled or disabled), or if command would interfere with another user of that domain (e.g. two gatherers have enabled a domain, both need to disable it for it to be disabled). Returns true otherwise.

Source:
Parameters:
Name Type Description
domain string
enable boolean
Returns:
Type:
boolean

_waitForCPUIdle(waitForCPUQuiet) → {Object}

Resolves when there have been no long tasks for at least waitForCPUQuiet ms.

Source:
Parameters:
Name Type Description
waitForCPUQuiet number
Returns:
Type:
Object

(private) _waitForFullyLoaded(pauseAfterLoadMs, networkQuietThresholdMs, cpuQuietThresholdMs, maxWaitForLoadedMs) → (non-null) {Promise}

Returns a promise that resolves when:

  • All of the following conditions have been met:
    • pauseAfterLoadMs milliseconds have passed since the load event.
    • networkQuietThresholdMs milliseconds have passed since the last network request that exceeded 2 inflight requests (network-2-quiet has been reached).
    • cpuQuietThresholdMs have passed since the last long task after network-2-quiet.
  • maxWaitForLoadedMs milliseconds have passed. See https://github.com/GoogleChrome/lighthouse/issues/627 for more.
Source:
Parameters:
Name Type Description
pauseAfterLoadMs number
networkQuietThresholdMs number
cpuQuietThresholdMs number
maxWaitForLoadedMs number
Returns:
Type:
Promise

(private) _waitForLoadEvent(pauseAfterLoadMs) → {Object}

Return a promise that resolves pauseAfterLoadMs after the load event fires and a method to cancel internal listeners and timeout.

Source:
Parameters:
Name Type Description
pauseAfterLoadMs number
Returns:
Type:
Object

(private) _waitForNetworkIdle(networkQuietThresholdMs) → {Object}

Returns a promise that resolves when the network has been idle (after DCL) for networkQuietThresholdMs ms and a method to cancel internal network listeners/timeout.

Source:
Parameters:
Name Type Description
networkQuietThresholdMs number
Returns:
Type:
Object

assertNoSameOriginServiceWorkerClients(pageUrlnon-null) → (non-null) {Promise}

Rejects if any open tabs would share a service worker with the target URL. This includes the target tab, so navigation to something like about:blank should be done before calling.

Source:
Parameters:
Name Type Description
pageUrl string
Returns:
Type:
Promise

beginDevtoolsLog()

Begin recording devtools protocol messages.

Source:

beginTrace(flagsopt)

Source:
Parameters:
Name Type Attributes Description
flags Object <optional>

blockUrlPatterns(urlsnon-null) → (non-null) {Promise}

Source:
Parameters:
Name Type Description
urls Array.<string>

URL patterns to block. Wildcards ('*') are allowed.

Returns:
Type:
Promise

cacheNatives() → (non-null) {Promise}

Cache native functions/objects inside window so we are sure polyfills do not overwrite the native implementations

Source:
Returns:
Type:
Promise

captureFunctionCallSites(funcName) → {function}

Keeps track of calls to a JS function and returns a list of {url, line, col} of the usage. Should be called before page load (in beforePass).

Source:
Parameters:
Name Type Description
funcName string

The function name to track ('Date.now', 'console.time').

Returns:
Type:
function

Call this method when you want results.

connect() → (non-null) {Promise.<null>}

Source:
Returns:
Type:
Promise.<null>

dismissJavaScriptDialogs() → (non-null) {Promise}

Dismiss JavaScript dialogs (alert, confirm, prompt), providing a generic promptText in case the dialog is a prompt.

Source:
Returns:
Type:
Promise

endDevtoolsLog() → (non-null) {Array.<{method: string, params: (!Object.<string, *>|undefined)}>}

Stop recording to devtoolsLog and return log contents.

Source:
Returns:
Type:
Array.<{method: string, params: (!Object.<string, *>|undefined)}>

evaluateAsync(expression, optionsopt) → (non-null) {Promise.<*>}

Evaluate an expression in the context of the current page. If useIsolation is true, the expression will be evaluated in a content script that has access to the page's DOM but whose JavaScript state is completely separate. Returns a promise that resolves on the expression's value.

Source:
Parameters:
Name Type Attributes Description
expression string
options Object <optional>
Returns:
Type:
Promise.<*>

evaluteScriptOnNewDocument(scriptSource) → (non-null) {Promise.<string>}

Add a script to run at load time of all future page loads.

Source:
Parameters:
Name Type Description
scriptSource string
Returns:
Type:
Promise.<string>

Identifier of the added script.

getElementsInDocument(pierceopt) → (non-null) {Promise.<!Array.<!Element>>}

Returns the flattened list of all DOM nodes within the document.

Source:
Parameters:
Name Type Attributes Default Description
pierce boolean <optional>
true

Whether to pierce through shadow trees and iframes. True by default.

Returns:
Type:
Promise.<!Array.<!Element>>

The found elements, or [], resolved in a promise

getObjectProperty(objectId, propName) → (non-null) {Promise.<string>}

Source:
Parameters:
Name Type Description
objectId string

Object ID for the resolved DOM node

propName string

Name of the property

Returns:
Type:
Promise.<string>

The property value, or null, if property not found

getRequestContent(requestId) → {string}

Return the body of the response with the given ID.

Source:
Parameters:
Name Type Description
requestId string
Returns:
Type:
string

getUserAgent() → (non-null) {Promise.<string>}

Source:
Returns:
Type:
Promise.<string>

goOffline() → (non-null) {Promise}

Emulate internet disconnection.

Source:
Returns:
Type:
Promise

goOnline(optionsnon-null) → (non-null) {Promise}

Enable internet connection, using emulated mobile settings if options.flags.disableNetworkThrottling is false.

Source:
Parameters:
Name Type Description
options Object
Returns:
Type:
Promise

gotoURL(url, optionsnon-null) → (non-null) {Promise.<string>}

Navigate to the given URL. Direct use of this method isn't advised: if the current page is already at the given URL, navigation will not occur and so the returned promise will only resolve after the MAX_WAIT_FOR_FULLY_LOADED timeout. See https://github.com/GoogleChrome/lighthouse/pull/185 for one possible workaround. Resolves on the url of the loaded page, taking into account any redirects.

Source:
Parameters:
Name Type Description
url string
options Object
Returns:
Type:
Promise.<string>

isDomainEnabled(domain) → {boolean}

Returns whether a domain is currently enabled.

Source:
Parameters:
Name Type Description
domain string
Returns:
Type:
boolean

off(eventNamenon-null, cb)

Unbind event listeners

Source:
Parameters:
Name Type Description
eventName string
cb function

on(eventNamenon-null, cb)

Bind listeners for protocol events

Source:
Parameters:
Name Type Description
eventName string
cb function

once(eventNamenon-null, cb)

Bind a one-time listener for protocol events. Listener is removed once it has been called.

Source:
Parameters:
Name Type Description
eventName string
cb function

queryPermissionState(name) → (non-null) {Promise.<string>}

Source:
Parameters:
Name Type Description
name string

The name of API whose permission you wish to query

Returns:
Type:
Promise.<string>

The state of permissions, resolved in a promise. See https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query.

querySelector(selector) → (non-null) {Promise.<Element>}

Source:
Parameters:
Name Type Description
selector string

Selector to find in the DOM

Returns:
Type:
Promise.<Element>

The found element, or null, resolved in a promise

querySelectorAll(selector) → (non-null) {Promise.<!Array.<!Element>>}

Source:
Parameters:
Name Type Description
selector string

Selector to find in the DOM

Returns:
Type:
Promise.<!Array.<!Element>>

The found elements, or [], resolved in a promise

registerPerformanceObserver() → (non-null) {Promise}

Install a performance observer that watches longtask timestamps for waitForCPUIdle.

Source:
Returns:
Type:
Promise

sendCommand(methodnon-null, paramsnon-null, cmdOptsopt) → (non-null) {Promise}

Call protocol methods

Source:
Parameters:
Name Type Attributes Description
method string
params Object
cmdOpts Object <optional>
Returns:
Type:
Promise