diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index d246bc7769e9..7bd9887557ae 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -701,6 +701,11 @@ class Driver { return collectUsage; } + + blockUrlPatterns(urlPatterns) { + const promiseArr = urlPatterns.map(url => this.sendCommand('Network.addBlockedURL', {url})); + return Promise.all(promiseArr); + } } /** diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index ae7286670fdf..6c155fe2d950 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -96,7 +96,8 @@ class GatherRunner { .then(_ => driver.enableRuntimeEvents()) .then(_ => driver.evaluateScriptOnLoad('window.__nativePromise = Promise;')) .then(_ => driver.cleanAndDisableBrowserCaches()) - .then(_ => driver.clearDataForOrigin(options.url)); + .then(_ => driver.clearDataForOrigin(options.url)) + .then(_ => driver.blockUrlPatterns(options.flags.blockedUrlPatterns || [])); } static disposeDriver(driver) { diff --git a/lighthouse-core/test/gather/fake-driver.js b/lighthouse-core/test/gather/fake-driver.js index 8ecc48c59a3b..6000704fca36 100644 --- a/lighthouse-core/test/gather/fake-driver.js +++ b/lighthouse-core/test/gather/fake-driver.js @@ -61,5 +61,8 @@ module.exports = { return Promise.resolve({ schemeIsCryptographic: true }); + }, + blockUrlPatterns() { + return Promise.resolve(); } };