From 1899e7931c427beb12428488593206b87b93c7fb Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 9 Jan 2019 15:47:08 -0800 Subject: [PATCH] feat: enable Network Service by default (#3738) References #3471. --- lib/Launcher.js | 1 + lib/NetworkManager.js | 9 ++++++++- test/network.spec.js | 9 --------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/Launcher.js b/lib/Launcher.js index 2cb617d906c30..7116205249b96 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -34,6 +34,7 @@ const CHROME_PROFILE_PATH = path.join(os.tmpdir(), 'puppeteer_dev_profile-'); const DEFAULT_ARGS = [ '--disable-background-networking', + '--enable-features=NetworkService,NetworkServiceInProcess', '--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows', '--disable-breakpad', diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index a5d5a78ac8cfa..26c05522150b4 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -135,7 +135,8 @@ class NetworkManager extends EventEmitter { * @param {!Protocol.Network.requestWillBeSentPayload} event */ _onRequestWillBeSent(event) { - if (this._protocolRequestInterceptionEnabled) { + // Request interception doesn't happen for data URLs with Network Service. + if (this._protocolRequestInterceptionEnabled && !event.request.url.startsWith('data:')) { const requestHash = generateRequestHash(event.request); const interceptionId = this._requestHashToInterceptionIds.firstValue(requestHash); if (interceptionId) { @@ -394,6 +395,9 @@ class Request { * @param {!{url?: string, method?:string, postData?: string, headers?: !Object}} overrides */ async continue(overrides = {}) { + // Request interception is not supported for data: urls. + if (this._url.startsWith('data:')) + return; assert(this._allowInterception, 'Request Interception is not enabled!'); assert(!this._interceptionHandled, 'Request is already handled!'); const { @@ -466,6 +470,9 @@ class Request { * @param {string=} errorCode */ async abort(errorCode = 'failed') { + // Request interception is not supported for data: urls. + if (this._url.startsWith('data:')) + return; const errorReason = errorReasons[errorCode]; assert(errorReason, 'Unknown error code: ' + errorCode); assert(this._allowInterception, 'Request Interception is not enabled!'); diff --git a/test/network.spec.js b/test/network.spec.js index 727735830c580..4e36a836118d0 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -495,15 +495,6 @@ module.exports.addTests = function({testRunner, expect}) { expect(requests.length).toBe(1); expect(requests[0].url()).toBe(dataURL); }); - it('should abort data server', async({page, server}) => { - await page.setRequestInterception(true); - page.on('request', request => { - request.abort(); - }); - let error = null; - await page.goto('data:text/html,No way!').catch(err => error = err); - expect(error.message).toContain('net::ERR_FAILED'); - }); it('should navigate to URL with hash and and fire requests without hash', async({page, server}) => { await page.setRequestInterception(true); const requests = [];