From d01aa6c84a1e41f15ffed3a8d36ad26a404a7187 Mon Sep 17 00:00:00 2001 From: Robin Richtsfeld Date: Thu, 20 May 2021 14:09:56 +0200 Subject: [PATCH] feat(requestinterception): remove cacheSafe flag (#7217) --- docs/api.md | 5 ++--- src/common/NetworkManager.ts | 13 ++----------- src/common/Page.ts | 11 ++--------- test/requestinterception.spec.ts | 15 +++++++++------ 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/docs/api.md b/docs/api.md index bcb114e8..13ecbb1c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -174,7 +174,7 @@ * [page.setGeolocation(options)](#pagesetgeolocationoptions) * [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled) * [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled) - * [page.setRequestInterception(value[, cacheSafe])](#pagesetrequestinterceptionvalue-cachesafe) + * [page.setRequestInterception(value)](#pagesetrequestinterceptionvalue) * [page.setUserAgent(userAgent)](#pagesetuseragentuseragent) * [page.setViewport(viewport)](#pagesetviewportviewport) * [page.tap(selector)](#pagetapselector) @@ -2218,10 +2218,9 @@ await page.setGeolocation({ latitude: 59.95, longitude: 30.31667 }); - `enabled` <[boolean]> When `true`, enables offline mode for the page. - returns: <[Promise]> -#### page.setRequestInterception(value[, cacheSafe]) +#### page.setRequestInterception(value) - `value` <[boolean]> Whether to enable request interception. -- `cacheSafe` <[boolean]> Whether to trust browser caching. If set to false, enabling request interception disables page caching. Defaults to false. - returns: <[Promise]> Activating request interception enables `request.abort`, `request.continue` and diff --git a/src/common/NetworkManager.ts b/src/common/NetworkManager.ts index e389580d..0fdb778d 100644 --- a/src/common/NetworkManager.ts +++ b/src/common/NetworkManager.ts @@ -114,7 +114,6 @@ export class NetworkManager extends EventEmitter { _credentials?: Credentials = null; _attemptedAuthentications = new Set(); _userRequestInterceptionEnabled = false; - _userRequestInterceptionCacheSafe = false; _protocolRequestInterceptionEnabled = false; _userCacheDisabled = false; _emulatedNetworkConditions: InternalNetworkConditions = { @@ -228,12 +227,8 @@ export class NetworkManager extends EventEmitter { await this._updateProtocolCacheDisabled(); } - async setRequestInterception( - value: boolean, - cacheSafe = false - ): Promise { + async setRequestInterception(value: boolean): Promise { this._userRequestInterceptionEnabled = value; - this._userRequestInterceptionCacheSafe = cacheSafe; await this._updateProtocolRequestInterception(); } @@ -258,11 +253,7 @@ export class NetworkManager extends EventEmitter { } _cacheDisabled(): boolean { - return ( - this._userCacheDisabled || - (this._userRequestInterceptionEnabled && - !this._userRequestInterceptionCacheSafe) - ); + return this._userCacheDisabled; } async _updateProtocolCacheDisabled(): Promise { diff --git a/src/common/Page.ts b/src/common/Page.ts index 9a617191..22f6421e 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -766,8 +766,6 @@ export class Page extends EventEmitter { /** * @param value - Whether to enable request interception. - * @param cacheSafe - Whether to trust browser caching. If set to false, - * enabling request interception disables page caching. Defaults to false. * * @remarks * Activating request interception enables {@link HTTPRequest.abort}, @@ -797,13 +795,8 @@ export class Page extends EventEmitter { * })(); * ``` */ - async setRequestInterception( - value: boolean, - cacheSafe = false - ): Promise { - return this._frameManager - .networkManager() - .setRequestInterception(value, cacheSafe); + async setRequestInterception(value: boolean): Promise { + return this._frameManager.networkManager().setRequestInterception(value); } /** diff --git a/test/requestinterception.spec.ts b/test/requestinterception.spec.ts index 57a06ac2..b2ca3f8b 100644 --- a/test/requestinterception.spec.ts +++ b/test/requestinterception.spec.ts @@ -495,13 +495,14 @@ describe('request interception', function () { expect(urls.has('one-style.html')).toBe(true); expect(urls.has('one-style.css')).toBe(true); }); - it('should not cache if not cache-safe', async () => { + it('should not cache if cache disabled', async () => { const { page, server } = getTestState(); // Load and re-load to make sure it's cached. await page.goto(server.PREFIX + '/cached/one-style.html'); - await page.setRequestInterception(true, false); + await page.setRequestInterception(true); + await page.setCacheEnabled(false); page.on('request', (request) => request.continue()); const cached = []; @@ -510,13 +511,14 @@ describe('request interception', function () { await page.reload(); expect(cached.length).toBe(0); }); - it('should cache if cache-safe', async () => { + it('should cache if cache enabled', async () => { const { page, server } = getTestState(); // Load and re-load to make sure it's cached. await page.goto(server.PREFIX + '/cached/one-style.html'); - await page.setRequestInterception(true, true); + await page.setRequestInterception(true); + await page.setCacheEnabled(true); page.on('request', (request) => request.continue()); const cached = []; @@ -525,10 +527,11 @@ describe('request interception', function () { await page.reload(); expect(cached.length).toBe(1); }); - it('should load fonts if cache-safe', async () => { + it('should load fonts if cache enabled', async () => { const { page, server } = getTestState(); - await page.setRequestInterception(true, true); + await page.setRequestInterception(true); + await page.setCacheEnabled(true); page.on('request', (request) => request.continue()); await page.goto(server.PREFIX + '/cached/one-style-font.html');