feat(requestinterception): remove cacheSafe flag (#7217)
This commit is contained in:
parent
97c9fe2520
commit
d01aa6c84a
@ -174,7 +174,7 @@
|
|||||||
* [page.setGeolocation(options)](#pagesetgeolocationoptions)
|
* [page.setGeolocation(options)](#pagesetgeolocationoptions)
|
||||||
* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
|
* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
|
||||||
* [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled)
|
* [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled)
|
||||||
* [page.setRequestInterception(value[, cacheSafe])](#pagesetrequestinterceptionvalue-cachesafe)
|
* [page.setRequestInterception(value)](#pagesetrequestinterceptionvalue)
|
||||||
* [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)
|
* [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)
|
||||||
* [page.setViewport(viewport)](#pagesetviewportviewport)
|
* [page.setViewport(viewport)](#pagesetviewportviewport)
|
||||||
* [page.tap(selector)](#pagetapselector)
|
* [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.
|
- `enabled` <[boolean]> When `true`, enables offline mode for the page.
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
#### page.setRequestInterception(value[, cacheSafe])
|
#### page.setRequestInterception(value)
|
||||||
|
|
||||||
- `value` <[boolean]> Whether to enable request interception.
|
- `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]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
Activating request interception enables `request.abort`, `request.continue` and
|
Activating request interception enables `request.abort`, `request.continue` and
|
||||||
|
@ -114,7 +114,6 @@ export class NetworkManager extends EventEmitter {
|
|||||||
_credentials?: Credentials = null;
|
_credentials?: Credentials = null;
|
||||||
_attemptedAuthentications = new Set<string>();
|
_attemptedAuthentications = new Set<string>();
|
||||||
_userRequestInterceptionEnabled = false;
|
_userRequestInterceptionEnabled = false;
|
||||||
_userRequestInterceptionCacheSafe = false;
|
|
||||||
_protocolRequestInterceptionEnabled = false;
|
_protocolRequestInterceptionEnabled = false;
|
||||||
_userCacheDisabled = false;
|
_userCacheDisabled = false;
|
||||||
_emulatedNetworkConditions: InternalNetworkConditions = {
|
_emulatedNetworkConditions: InternalNetworkConditions = {
|
||||||
@ -228,12 +227,8 @@ export class NetworkManager extends EventEmitter {
|
|||||||
await this._updateProtocolCacheDisabled();
|
await this._updateProtocolCacheDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setRequestInterception(
|
async setRequestInterception(value: boolean): Promise<void> {
|
||||||
value: boolean,
|
|
||||||
cacheSafe = false
|
|
||||||
): Promise<void> {
|
|
||||||
this._userRequestInterceptionEnabled = value;
|
this._userRequestInterceptionEnabled = value;
|
||||||
this._userRequestInterceptionCacheSafe = cacheSafe;
|
|
||||||
await this._updateProtocolRequestInterception();
|
await this._updateProtocolRequestInterception();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,11 +253,7 @@ export class NetworkManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_cacheDisabled(): boolean {
|
_cacheDisabled(): boolean {
|
||||||
return (
|
return this._userCacheDisabled;
|
||||||
this._userCacheDisabled ||
|
|
||||||
(this._userRequestInterceptionEnabled &&
|
|
||||||
!this._userRequestInterceptionCacheSafe)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _updateProtocolCacheDisabled(): Promise<void> {
|
async _updateProtocolCacheDisabled(): Promise<void> {
|
||||||
|
@ -766,8 +766,6 @@ export class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value - Whether to enable request interception.
|
* @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
|
* @remarks
|
||||||
* Activating request interception enables {@link HTTPRequest.abort},
|
* Activating request interception enables {@link HTTPRequest.abort},
|
||||||
@ -797,13 +795,8 @@ export class Page extends EventEmitter {
|
|||||||
* })();
|
* })();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
async setRequestInterception(
|
async setRequestInterception(value: boolean): Promise<void> {
|
||||||
value: boolean,
|
return this._frameManager.networkManager().setRequestInterception(value);
|
||||||
cacheSafe = false
|
|
||||||
): Promise<void> {
|
|
||||||
return this._frameManager
|
|
||||||
.networkManager()
|
|
||||||
.setRequestInterception(value, cacheSafe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -495,13 +495,14 @@ describe('request interception', function () {
|
|||||||
expect(urls.has('one-style.html')).toBe(true);
|
expect(urls.has('one-style.html')).toBe(true);
|
||||||
expect(urls.has('one-style.css')).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();
|
const { page, server } = getTestState();
|
||||||
|
|
||||||
// Load and re-load to make sure it's cached.
|
// Load and re-load to make sure it's cached.
|
||||||
await page.goto(server.PREFIX + '/cached/one-style.html');
|
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());
|
page.on('request', (request) => request.continue());
|
||||||
|
|
||||||
const cached = [];
|
const cached = [];
|
||||||
@ -510,13 +511,14 @@ describe('request interception', function () {
|
|||||||
await page.reload();
|
await page.reload();
|
||||||
expect(cached.length).toBe(0);
|
expect(cached.length).toBe(0);
|
||||||
});
|
});
|
||||||
it('should cache if cache-safe', async () => {
|
it('should cache if cache enabled', async () => {
|
||||||
const { page, server } = getTestState();
|
const { page, server } = getTestState();
|
||||||
|
|
||||||
// Load and re-load to make sure it's cached.
|
// Load and re-load to make sure it's cached.
|
||||||
await page.goto(server.PREFIX + '/cached/one-style.html');
|
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());
|
page.on('request', (request) => request.continue());
|
||||||
|
|
||||||
const cached = [];
|
const cached = [];
|
||||||
@ -525,10 +527,11 @@ describe('request interception', function () {
|
|||||||
await page.reload();
|
await page.reload();
|
||||||
expect(cached.length).toBe(1);
|
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();
|
const { page, server } = getTestState();
|
||||||
|
|
||||||
await page.setRequestInterception(true, true);
|
await page.setRequestInterception(true);
|
||||||
|
await page.setCacheEnabled(true);
|
||||||
page.on('request', (request) => request.continue());
|
page.on('request', (request) => request.continue());
|
||||||
|
|
||||||
await page.goto(server.PREFIX + '/cached/one-style-font.html');
|
await page.goto(server.PREFIX + '/cached/one-style-font.html');
|
||||||
|
Loading…
Reference in New Issue
Block a user