From d5e8602a62b0c03681a103c18c59b8f629adca98 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 29 Jan 2020 12:22:15 -0800 Subject: [PATCH] addressed comments --- docs/api.md | 12 ++++++------ src/firefox/ffPage.ts | 2 ++ test/browsercontext.spec.js | 10 ++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/api.md b/docs/api.md index ce6ecb4519..908790334a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -212,7 +212,7 @@ Indicates that the browser is connected. - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `userAgent` Specific user agent to use in this context. - - `cacheEnabled` Toggles page cache in the context. By defaul caching is enabled. + - `cacheEnabled` Toggles HTTP cache in the context. By default HTTP cache is enabled. - `interceptNetwork` Toggles network interception in the context. Defaults to false. - `offlineMode` Toggles offline network mode in the context. Defaults to false. - `javaScriptEnabled` Whether or not to enable or disable JavaScript in the context. Defaults to true. @@ -328,10 +328,10 @@ Creates a new page in the browser context and optionally navigates it to the spe An array of all pages inside the browser context. #### browserContext.setCacheEnabled([enabled]) -- `enabled` <[boolean]> sets the `enabled` state of the cache. +- `enabled` <[boolean]> sets the `enabled` state of the HTTP cache. - returns: <[Promise]> -Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled. +Toggles ignoring HTTP cache for each request based on the enabled state. By default, HTTP cache is enabled. #### browserContext.setCookies(cookies) - `cookies` <[Array]<[Object]>> @@ -366,7 +366,7 @@ await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667}); > **NOTE** Consider using [browserContext.setPermissions](#browsercontextsetpermissions-permissions) to grant permissions for the page to read its geolocation. #### browserContext.setOfflineMode(enabled) -- `enabled` <[boolean]> When `true`, enables offline mode for the page. +- `enabled` <[boolean]> When `true`, enables offline mode for the context. - returns: <[Promise]> #### browserContext.setPermissions(origin, permissions[]) @@ -401,7 +401,7 @@ await context.setPermissions('https://html5demos.com', ['geolocation']); - returns: <[Promise]> Activating request interception enables `request.abort`, `request.continue` and -`request.respond` methods. This provides the capability to modify network requests that are made by a page. +`request.respond` methods. This provides the capability to modify network requests that are made by all pages in the context. Once request interception is enabled, every request will stall unless it's continued, responded or aborted. An example of a naïve request interceptor that aborts all image requests: @@ -420,7 +420,7 @@ await page.goto('https://example.com'); await browser.close(); ``` -> **NOTE** Enabling request interception disables page caching. +> **NOTE** Enabling request interception disables HTTP cache. ### class: Page diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.ts index acd10bd0de..b09384449e 100644 --- a/src/firefox/ffPage.ts +++ b/src/firefox/ffPage.ts @@ -92,6 +92,8 @@ export class FFPage implements PageDelegate { promises.push(this._session.send('Page.setUserAgent', { userAgent: options.userAgent })); if (options.cacheEnabled === false) promises.push(this.setCacheEnabled(false)); + if (options.interceptNetwork) + promises.push(this.setRequestInterception(true)); await Promise.all(promises); } diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.js index eef6cc6ef2..90525a545e 100644 --- a/test/browsercontext.spec.js +++ b/test/browsercontext.spec.js @@ -339,4 +339,14 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE expect(cachedRequest.headers['if-modified-since']).toBe(undefined); }); }); + + describe('BrowserContext({interceptNetwork})', function() { + it('should enable request interception', async({newPage, httpsServer}) => { + const page = await newPage({ ignoreHTTPSErrors: true, interceptNetwork: true }); + page.on('request', request => request.abort()); + let error; + await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e); + expect(error).toBeTruthy(); + }); + }); };