From 5ba6621cde5d0721f017fdb6befde6f8d9fb87a6 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 15 Jun 2017 08:23:48 -0700 Subject: [PATCH] Remove the Page.setBlockedURLs method This patch removes the Page.setBlockedURLs method. The functionality is trivially implementable with the request interception (see examples/loadurlwithoutcss.js). Fixes #1. --- docs/api.md | 6 ------ examples/loadurlwithoutcss.js | 7 ++++++- lib/Page.js | 13 ------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/docs/api.md b/docs/api.md index 7564e251..84fca31f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -7,7 +7,6 @@ - [browser.version()](#browserversion) - [browser.close()](#browserclose) - [class: Page](#class-page) - - [page.setBlockedURLs(patterns)](#pagesetblockedurlspatterns) - [page.addScriptTag(url)](#pageaddscripttagurl) - [page.injectFile(filePath)](#pageinjectfilefilepath) - [page.setInPageCallback(name, callback)](#pagesetinpagecallbackname-callback) @@ -75,11 +74,6 @@ browser.newPage().then(page => { ``` Pages could be closed by `page.close()` method. -#### page.setBlockedURLs(patterns) - -- `patterns` [<Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) -- returns: [<Promise>](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promise which resolves when blocked URLs have been successfully set. - #### page.addScriptTag(url) - `url` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Url of a script to be added diff --git a/examples/loadurlwithoutcss.js b/examples/loadurlwithoutcss.js index 8cb76019..e11f6a9c 100644 --- a/examples/loadurlwithoutcss.js +++ b/examples/loadurlwithoutcss.js @@ -25,7 +25,12 @@ var address = process.argv[2]; var browser = new Browser({headless: false}); browser.newPage().then(async page => { - await page.setBlockedURLs(['*.css']); + page.setRequestInterceptor(request => { + if (request.url().endsWith('.css')) + request.abort(); + else + request.continue(); + }); var success = await page.navigate(address); if (!success) console.log('Unable to load the address!'); diff --git a/lib/Page.js b/lib/Page.js index 4f76771b..74034284 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -55,8 +55,6 @@ class Page extends EventEmitter { this._sourceURLToPageCallback = new Map(); /** @type {!Map} */ this._scriptIdToPageCallback = new Map(); - /** @type {!Array} */ - this._blockedURLs = []; /** @type {?function(!Request)} */ this._requestInterceptor = null; @@ -86,17 +84,6 @@ class Page extends EventEmitter { this._requestInterceptor(request); } - /** - * @param {!Array} patterns - * @return {!Promise} - */ - async setBlockedURLs(patterns) { - this._blockedURLs = patterns; - await this._client.send('Network.setBlockedURLs', { - urls: patterns - }); - } - /** * @param {string} url * @return {!Promise}