diff --git a/lib/extensionserver/index.js b/lib/extensionserver/index.js index 13e55444c..df7294691 100644 --- a/lib/extensionserver/index.js +++ b/lib/extensionserver/index.js @@ -18,7 +18,6 @@ export class ExtensionServer { (options.cacheClearRaw || options.requestheader || options.block || - options.basicAuth || options.cookie || options.clearCacheKeepCookies) ? true diff --git a/lib/firefox/firefoxBidi.js b/lib/firefox/firefoxBidi.js index 64b80ebff..1aa2a725d 100644 --- a/lib/firefox/firefoxBidi.js +++ b/lib/firefox/firefoxBidi.js @@ -1,10 +1,12 @@ +import { Bidi } from '../core/engine/command/bidi.js'; import intel from 'intel'; const log = intel.getLogger('browsertime.firefox.bidi'); export class FirefoxBidi { - constructor(bidi, browsingContextId, options) { + constructor(bidi, browsingContextId, driver, options) { this.options = options; this.bidi = bidi; + this.driver = driver; this.browsingContextId = browsingContextId; } @@ -22,4 +24,38 @@ export class FirefoxBidi { log.error('Could not inject JavaScript:' + error); } } + + async setBasicAuth(basicAuth) { + const parts = basicAuth.split('@'); + const bidi = new Bidi(this.driver, this.options.browser); + + const command = { + method: 'network.addIntercept', + params: { + phases: ['authRequired'] + } + }; + await bidi.send(command); + + await bidi.subscribe('network.authRequired'); + + await bidi.onMessage(async function (event) { + const parsedEvent = JSON.parse(Buffer.from(event.toString())); + if (parsedEvent.method === 'network.authRequired') { + const continueWithAuth = { + method: 'network.continueWithAuth', + params: { + request: parsedEvent.params.request.request, + action: 'provideCredentials', + credentials: { + type: 'password', + username: parts[0], + password: parts[1] + } + } + }; + await bidi.send(continueWithAuth); + } + }); + } } diff --git a/lib/firefox/webdriver/firefox.js b/lib/firefox/webdriver/firefox.js index e7272278f..f906ed600 100644 --- a/lib/firefox/webdriver/firefox.js +++ b/lib/firefox/webdriver/firefox.js @@ -67,6 +67,7 @@ export class Firefox { this.bidi = new FirefoxBidi( await runner.getDriver().getBidi(), this.windowId, + runner.getDriver(), this.options ); } @@ -90,6 +91,10 @@ export class Firefox { await this.bidi.injectJavaScript(this.options.injectJs); } + if (this.options.basicAuth) { + await this.bidi.setBasicAuth(this.options.basicAuth); + } + if ( this.firefoxConfig.appendToUserAgent || this.options.appendToUserAgent