mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
api: remove Page.setCacheEnabled (#1231)
This commit is contained in:
parent
1bf5b61cbb
commit
aabdac8380
11
docs/api.md
11
docs/api.md
@ -209,7 +209,7 @@ Indicates that the browser is connected.
|
|||||||
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
|
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
|
||||||
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
|
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
|
||||||
- `extraHTTPHeaders` <[Object]> An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
- `extraHTTPHeaders` <[Object]> An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||||
- `offline` <[boolean]> Whether to emulate network being offline for the browser context.
|
- `offline` <[boolean]> Whether to emulate network being offline. Defaults to `false`.
|
||||||
- returns: <[Promise]<[BrowserContext]>>
|
- returns: <[Promise]<[BrowserContext]>>
|
||||||
|
|
||||||
Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||||
@ -244,7 +244,7 @@ Creates a new browser context. It won't share cookies/cache with other browser c
|
|||||||
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
|
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
|
||||||
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
|
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
|
||||||
- `extraHTTPHeaders` <[Object]> An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
- `extraHTTPHeaders` <[Object]> An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||||
- `offline` <[boolean]> Whether to emulate network being offline for the browser context.
|
- `offline` <[boolean]> Whether to emulate network being offline. Defaults to `false`.
|
||||||
- returns: <[Promise]<[Page]>>
|
- returns: <[Promise]<[Page]>>
|
||||||
|
|
||||||
Creates a new page in a new browser context. Closing this page will close the context as well.
|
Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||||
@ -637,7 +637,6 @@ page.removeListener('request', logRequest);
|
|||||||
- [page.route(url, handler)](#pagerouteurl-handler)
|
- [page.route(url, handler)](#pagerouteurl-handler)
|
||||||
- [page.screenshot([options])](#pagescreenshotoptions)
|
- [page.screenshot([options])](#pagescreenshotoptions)
|
||||||
- [page.select(selector, value[, options])](#pageselectselector-value-options)
|
- [page.select(selector, value[, options])](#pageselectselector-value-options)
|
||||||
- [page.setCacheEnabled([enabled])](#pagesetcacheenabledenabled)
|
|
||||||
- [page.setContent(html[, options])](#pagesetcontenthtml-options)
|
- [page.setContent(html[, options])](#pagesetcontenthtml-options)
|
||||||
- [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout)
|
- [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout)
|
||||||
- [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout)
|
- [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout)
|
||||||
@ -1434,12 +1433,6 @@ page.select('select#colors', { value: 'blue' }, { index: 2 }, 'red');
|
|||||||
|
|
||||||
Shortcut for [page.mainFrame().select()](#frameselectselector-values)
|
Shortcut for [page.mainFrame().select()](#frameselectselector-values)
|
||||||
|
|
||||||
#### page.setCacheEnabled([enabled])
|
|
||||||
- `enabled` <[boolean]> sets the `enabled` state of the cache. Defaults to `true`.
|
|
||||||
- returns: <[Promise]>
|
|
||||||
|
|
||||||
Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled.
|
|
||||||
|
|
||||||
#### page.setContent(html[, options])
|
#### page.setContent(html[, options])
|
||||||
- `html` <[string]> HTML markup to assign to the page.
|
- `html` <[string]> HTML markup to assign to the page.
|
||||||
- `options` <[Object]> Parameters which might have the following properties:
|
- `options` <[Object]> Parameters which might have the following properties:
|
||||||
|
@ -33,7 +33,6 @@ export class CRNetworkManager {
|
|||||||
private _attemptedAuthentications = new Set<string>();
|
private _attemptedAuthentications = new Set<string>();
|
||||||
private _userRequestInterceptionEnabled = false;
|
private _userRequestInterceptionEnabled = false;
|
||||||
private _protocolRequestInterceptionEnabled = false;
|
private _protocolRequestInterceptionEnabled = false;
|
||||||
private _userCacheDisabled = false;
|
|
||||||
private _requestIdToInterceptionId = new Map<string, string>();
|
private _requestIdToInterceptionId = new Map<string, string>();
|
||||||
private _eventListeners: RegisteredListener[];
|
private _eventListeners: RegisteredListener[];
|
||||||
|
|
||||||
@ -77,11 +76,6 @@ export class CRNetworkManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCacheEnabled(enabled: boolean) {
|
|
||||||
this._userCacheDisabled = !enabled;
|
|
||||||
await this._updateProtocolCacheDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
async setRequestInterception(value: boolean) {
|
async setRequestInterception(value: boolean) {
|
||||||
this._userRequestInterceptionEnabled = value;
|
this._userRequestInterceptionEnabled = value;
|
||||||
await this._updateProtocolRequestInterception();
|
await this._updateProtocolRequestInterception();
|
||||||
@ -94,7 +88,7 @@ export class CRNetworkManager {
|
|||||||
this._protocolRequestInterceptionEnabled = enabled;
|
this._protocolRequestInterceptionEnabled = enabled;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._updateProtocolCacheDisabled(),
|
this._client.send('Network.setCacheDisabled', { cacheDisabled: true }),
|
||||||
this._client.send('Fetch.enable', {
|
this._client.send('Fetch.enable', {
|
||||||
handleAuthRequests: true,
|
handleAuthRequests: true,
|
||||||
patterns: [{urlPattern: '*'}],
|
patterns: [{urlPattern: '*'}],
|
||||||
@ -102,18 +96,12 @@ export class CRNetworkManager {
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._updateProtocolCacheDisabled(),
|
this._client.send('Network.setCacheDisabled', { cacheDisabled: false }),
|
||||||
this._client.send('Fetch.disable')
|
this._client.send('Fetch.disable')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _updateProtocolCacheDisabled() {
|
|
||||||
await this._client.send('Network.setCacheDisabled', {
|
|
||||||
cacheDisabled: this._userCacheDisabled || this._protocolRequestInterceptionEnabled
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_onRequestWillBeSent(event: Protocol.Network.requestWillBeSentPayload) {
|
_onRequestWillBeSent(event: Protocol.Network.requestWillBeSentPayload) {
|
||||||
// Request interception doesn't happen for data URLs with Network Service.
|
// Request interception doesn't happen for data URLs with Network Service.
|
||||||
if (this._protocolRequestInterceptionEnabled && !event.request.url.startsWith('data:')) {
|
if (this._protocolRequestInterceptionEnabled && !event.request.url.startsWith('data:')) {
|
||||||
|
@ -372,10 +372,6 @@ export class CRPage implements PageDelegate {
|
|||||||
await this._client.send('Emulation.setEmulatedMedia', { media: mediaType || '', features });
|
await this._client.send('Emulation.setEmulatedMedia', { media: mediaType || '', features });
|
||||||
}
|
}
|
||||||
|
|
||||||
setCacheEnabled(enabled: boolean): Promise<void> {
|
|
||||||
return this._networkManager.setCacheEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
async setRequestInterception(enabled: boolean): Promise<void> {
|
async setRequestInterception(enabled: boolean): Promise<void> {
|
||||||
await this._networkManager.setRequestInterception(enabled);
|
await this._networkManager.setRequestInterception(enabled);
|
||||||
}
|
}
|
||||||
|
@ -271,10 +271,6 @@ export class FFPage implements PageDelegate {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCacheEnabled(enabled: boolean): Promise<void> {
|
|
||||||
await this._session.send('Page.setCacheDisabled', {cacheDisabled: !enabled});
|
|
||||||
}
|
|
||||||
|
|
||||||
async setRequestInterception(enabled: boolean): Promise<void> {
|
async setRequestInterception(enabled: boolean): Promise<void> {
|
||||||
await this._networkManager.setRequestInterception(enabled);
|
await this._networkManager.setRequestInterception(enabled);
|
||||||
}
|
}
|
||||||
|
10
src/page.ts
10
src/page.ts
@ -48,7 +48,6 @@ export interface PageDelegate {
|
|||||||
updateExtraHTTPHeaders(): Promise<void>;
|
updateExtraHTTPHeaders(): Promise<void>;
|
||||||
setViewportSize(viewportSize: types.Size): Promise<void>;
|
setViewportSize(viewportSize: types.Size): Promise<void>;
|
||||||
setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void>;
|
setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void>;
|
||||||
setCacheEnabled(enabled: boolean): Promise<void>;
|
|
||||||
setRequestInterception(enabled: boolean): Promise<void>;
|
setRequestInterception(enabled: boolean): Promise<void>;
|
||||||
authenticate(credentials: types.Credentials | null): Promise<void>;
|
authenticate(credentials: types.Credentials | null): Promise<void>;
|
||||||
setFileChooserIntercepted(enabled: boolean): Promise<void>;
|
setFileChooserIntercepted(enabled: boolean): Promise<void>;
|
||||||
@ -79,7 +78,6 @@ type PageState = {
|
|||||||
mediaType: types.MediaType | null;
|
mediaType: types.MediaType | null;
|
||||||
colorScheme: types.ColorScheme | null;
|
colorScheme: types.ColorScheme | null;
|
||||||
extraHTTPHeaders: network.Headers | null;
|
extraHTTPHeaders: network.Headers | null;
|
||||||
cacheEnabled: boolean | null;
|
|
||||||
interceptNetwork: boolean | null;
|
interceptNetwork: boolean | null;
|
||||||
credentials: types.Credentials | null;
|
credentials: types.Credentials | null;
|
||||||
hasTouch: boolean | null;
|
hasTouch: boolean | null;
|
||||||
@ -145,7 +143,6 @@ export class Page extends platform.EventEmitter {
|
|||||||
mediaType: null,
|
mediaType: null,
|
||||||
colorScheme: null,
|
colorScheme: null,
|
||||||
extraHTTPHeaders: null,
|
extraHTTPHeaders: null,
|
||||||
cacheEnabled: null,
|
|
||||||
interceptNetwork: null,
|
interceptNetwork: null,
|
||||||
credentials: null,
|
credentials: null,
|
||||||
hasTouch: null,
|
hasTouch: null,
|
||||||
@ -390,13 +387,6 @@ export class Page extends platform.EventEmitter {
|
|||||||
await this._delegate.evaluateOnNewDocument(await helper.evaluationScript(script, args));
|
await this._delegate.evaluateOnNewDocument(await helper.evaluationScript(script, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCacheEnabled(enabled: boolean = true) {
|
|
||||||
if (this._state.cacheEnabled === enabled)
|
|
||||||
return;
|
|
||||||
this._state.cacheEnabled = enabled;
|
|
||||||
await this._delegate.setCacheEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
async route(url: types.URLMatch, handler: (request: network.Request) => void) {
|
async route(url: types.URLMatch, handler: (request: network.Request) => void) {
|
||||||
if (!this._state.interceptNetwork) {
|
if (!this._state.interceptNetwork) {
|
||||||
this._state.interceptNetwork = true;
|
this._state.interceptNetwork = true;
|
||||||
|
@ -129,8 +129,6 @@ export class WKPage implements PageDelegate {
|
|||||||
|
|
||||||
if (this._page._state.interceptNetwork)
|
if (this._page._state.interceptNetwork)
|
||||||
promises.push(session.send('Network.setInterceptionEnabled', { enabled: true, interceptRequests: true }));
|
promises.push(session.send('Network.setInterceptionEnabled', { enabled: true, interceptRequests: true }));
|
||||||
if (this._page._state.cacheEnabled === false)
|
|
||||||
promises.push(session.send('Network.setResourceCachingDisabled', { disabled: true }));
|
|
||||||
|
|
||||||
const contextOptions = this._page.context()._options;
|
const contextOptions = this._page.context()._options;
|
||||||
if (contextOptions.userAgent)
|
if (contextOptions.userAgent)
|
||||||
@ -422,11 +420,6 @@ export class WKPage implements PageDelegate {
|
|||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCacheEnabled(enabled: boolean): Promise<void> {
|
|
||||||
const disabled = !enabled;
|
|
||||||
await this._updateState('Network.setResourceCachingDisabled', { disabled });
|
|
||||||
}
|
|
||||||
|
|
||||||
async setRequestInterception(enabled: boolean): Promise<void> {
|
async setRequestInterception(enabled: boolean): Promise<void> {
|
||||||
await this._updateState('Network.setInterceptionEnabled', { enabled, interceptRequests: enabled });
|
await this._updateState('Network.setInterceptionEnabled', { enabled, interceptRequests: enabled });
|
||||||
}
|
}
|
||||||
|
@ -1027,8 +1027,6 @@ module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FF
|
|||||||
expect(error.stack).toContain('Frame.goto')
|
expect(error.stack).toContain('Frame.goto')
|
||||||
});
|
});
|
||||||
it('should return matching responses', async({page, server}) => {
|
it('should return matching responses', async({page, server}) => {
|
||||||
// Disable cache: otherwise, chromium will cache similar requests.
|
|
||||||
await page.setCacheEnabled(false);
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Attach three frames.
|
// Attach three frames.
|
||||||
const frames = [
|
const frames = [
|
||||||
@ -1036,13 +1034,14 @@ module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FF
|
|||||||
await utils.attachFrame(page, 'frame2', server.EMPTY_PAGE),
|
await utils.attachFrame(page, 'frame2', server.EMPTY_PAGE),
|
||||||
await utils.attachFrame(page, 'frame3', server.EMPTY_PAGE),
|
await utils.attachFrame(page, 'frame3', server.EMPTY_PAGE),
|
||||||
];
|
];
|
||||||
// Navigate all frames to the same URL.
|
|
||||||
const serverResponses = [];
|
const serverResponses = [];
|
||||||
server.setRoute('/one-style.html', (req, res) => serverResponses.push(res));
|
server.setRoute('/0.html', (req, res) => serverResponses.push(res));
|
||||||
|
server.setRoute('/1.html', (req, res) => serverResponses.push(res));
|
||||||
|
server.setRoute('/2.html', (req, res) => serverResponses.push(res));
|
||||||
const navigations = [];
|
const navigations = [];
|
||||||
for (let i = 0; i < 3; ++i) {
|
for (let i = 0; i < 3; ++i) {
|
||||||
navigations.push(frames[i].goto(server.PREFIX + '/one-style.html'));
|
navigations.push(frames[i].goto(server.PREFIX + '/' + i + '.html'));
|
||||||
await server.waitForRequest('/one-style.html');
|
await server.waitForRequest('/' + i + '.html');
|
||||||
}
|
}
|
||||||
// Respond from server out-of-order.
|
// Respond from server out-of-order.
|
||||||
const serverResponseTexts = ['AAA', 'BBB', 'CCC'];
|
const serverResponseTexts = ['AAA', 'BBB', 'CCC'];
|
||||||
|
@ -756,29 +756,6 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Page.setCacheEnabled', function() {
|
|
||||||
it('should enable or disable the cache based on the state passed', async({page, server}) => {
|
|
||||||
await page.goto(server.PREFIX + '/cached/one-style.html');
|
|
||||||
// WebKit does r.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData);
|
|
||||||
// when navigating to the same url, load empty.html to avoid that.
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
|
||||||
const [cachedRequest] = await Promise.all([
|
|
||||||
server.waitForRequest('/cached/one-style.html'),
|
|
||||||
page.goto(server.PREFIX + '/cached/one-style.html'),
|
|
||||||
]);
|
|
||||||
// Rely on "if-modified-since" caching in our test server.
|
|
||||||
expect(cachedRequest.headers['if-modified-since']).not.toBe(undefined);
|
|
||||||
|
|
||||||
await page.setCacheEnabled(false);
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
|
||||||
const [nonCachedRequest] = await Promise.all([
|
|
||||||
server.waitForRequest('/cached/one-style.html'),
|
|
||||||
page.goto(server.PREFIX + '/cached/one-style.html'),
|
|
||||||
]);
|
|
||||||
expect(nonCachedRequest.headers['if-modified-since']).toBe(undefined);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Page.title', function() {
|
describe('Page.title', function() {
|
||||||
it('should return the page title', async({page, server}) => {
|
it('should return the page title', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/title.html');
|
await page.goto(server.PREFIX + '/title.html');
|
||||||
|
Loading…
Reference in New Issue
Block a user