diff --git a/docs/api.md b/docs/api.md index bcb114e888add..13ecbb1c6ff69 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 e389580d42f95..0fdb778d4d54e 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 9a6171913f20a..22f6421ecf89b 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 57a06ac251e6a..b2ca3f8b4fd35 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');