mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Page): add setCacheEnabled(enabled)
to Page object (#1609)
This change adds in the `Page.setCacheEnabled(enabled)` method to toggle ignoring cache for each request. Fixes #1556.
This commit is contained in:
parent
18a1fb9385
commit
ac1b9a0eb0
@ -86,6 +86,7 @@
|
||||
* [page.reload(options)](#pagereloadoptions)
|
||||
* [page.screenshot([options])](#pagescreenshotoptions)
|
||||
* [page.select(selector, ...values)](#pageselectselector-values)
|
||||
* [page.setCacheEnabled(enabled)](#pagesetcacheenabledenabled)
|
||||
* [page.setContent(html)](#pagesetcontenthtml)
|
||||
* [page.setCookie(...cookies)](#pagesetcookiecookies)
|
||||
* [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout)
|
||||
@ -1150,6 +1151,12 @@ page.select('select#colors', 'red', 'green', 'blue'); // multiple selections
|
||||
|
||||
Shortcut for [page.mainFrame().select()](#frameselectselector-values)
|
||||
|
||||
#### page.setCacheEnabled(enabled)
|
||||
- `enabled` <[boolean]> sets the `enabled` state of the cache.
|
||||
- returns: <[Promise]>
|
||||
|
||||
Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled.
|
||||
|
||||
#### page.setContent(html)
|
||||
- `html` <[string]> HTML markup to assign to the page.
|
||||
- returns: <[Promise]>
|
||||
|
@ -650,6 +650,14 @@ class Page extends EventEmitter {
|
||||
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Boolean} enabled
|
||||
* @returns {!Promise}
|
||||
*/
|
||||
async setCacheEnabled(enabled = true) {
|
||||
await this._client.send('Network.setCacheDisabled', {cacheDisabled: !enabled});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object=} options
|
||||
* @return {!Promise<!Buffer>}
|
||||
|
15
test/test.js
15
test/test.js
@ -3050,6 +3050,21 @@ describe('Page', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.setCacheEnabled', function() {
|
||||
it('should enable or disable the cache based on the state passed', async({page, server}) => {
|
||||
const responses = new Map();
|
||||
page.on('response', r => responses.set(r.url().split('/').pop(), r));
|
||||
|
||||
await page.goto(server.PREFIX + '/cached/one-style.html', {waitUntil: 'networkidle2'});
|
||||
await page.reload({waitUntil: 'networkidle2'});
|
||||
expect(responses.get('one-style.css').fromCache()).toBe(true);
|
||||
|
||||
await page.setCacheEnabled(false);
|
||||
await page.reload({waitUntil: 'networkidle2'});
|
||||
expect(responses.get('one-style.css').fromCache()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Printing to pdf is currently only supported in headless
|
||||
(headless ? describe : xdescribe)('Page.pdf', function() {
|
||||
it('should be able to save file', async({page, server}) => {
|
||||
|
Loading…
Reference in New Issue
Block a user