diff --git a/examples/loadurlwithoutcss.js b/examples/loadurlwithoutcss.js new file mode 100644 index 00000000..09477715 --- /dev/null +++ b/examples/loadurlwithoutcss.js @@ -0,0 +1,33 @@ +/** + * Copyright 2017 Google Inc., PhantomJS Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var Browser = require('../lib/Browser'); + +if (process.argv.length < 3) { + console.log('Usage: loadurlwithoutcss.js URL'); + return; +} + +var address = process.argv[2]; + +var browser = new Browser({headless: false}); +browser.newPage().then(async page => { + await page.setBlockedURLs(['*.css']); + var success = await page.navigate(address); + if (!success) + console.log('Unable to load the address!'); +// browser.close(); +}); diff --git a/lib/Page.js b/lib/Page.js index 00974e11..38c6c87e 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -54,6 +54,8 @@ class Page extends EventEmitter { this._sourceURLToPageCallback = new Map(); /** @type {!Map} */ this._scriptIdToPageCallback = new Map(); + /** @type {!Array} */ + this._blockedURLs = []; client.on('Debugger.paused', event => this._onDebuggerPaused(event)); client.on('Debugger.scriptParsed', event => this._onScriptParsed(event)); @@ -64,6 +66,17 @@ class Page extends EventEmitter { client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails)); } + /** + * @param {!Array} patterns + * @return {!Promise} + */ + async setBlockedURLs(patterns) { + this._blockedURLs = patterns; + await this._client.send('Network.setBlockedURLs', { + urls: patterns + }); + } + /** * @param {string} url * @return {!Promise}