-
Notifications
You must be signed in to change notification settings - Fork 9.3k
feat(Page): add setCacheEnabled(enabled) to Page object
#1609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name this page.setCacheEnabled to be aligned with page.setJavascriptEnabled method that we already have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made these changes 👍
disableCache() to Page objectsetCacheEnabled() to Page object
setCacheEnabled() to Page objectsetCacheEnabled(enabled) to Page object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewwwcollins The fromCache/fromServiceWorker methods are just landed: #1971. Are you interesteed in landing this PR? It would be nice have.
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add:
By default, caching is enabled.
test/test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use one of the test/assets/cached/ assets intead of chromestatus.com website? We aim for the hermetic tests.
|
@aslushnikov - I have made these changes now. |
3d67b13 to
550ea85
Compare
test/test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two nits:
- Let's start from making sure it's cached, and then busting caching with this method
- Can we load-and-reload initially to make sure the stylesheet is cached?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made these changes now. I needed to reset the responses array twice. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I sent a comment but for some reason it didn't get posted to github.
Let me re-type it here:
I needed to reset the responses array twice. What do you think?
You can avoid this by subscribing after the page.goto. You can also save a few lines by storing resources in the map:
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));
await page.goto(server.PREFIX + '/cached/one-style.html');
await page.reload();
expect(responses.get('one-style.css').fromCache()).toBe(true);
await page.setCacheEnabled(false);
await page.reload();
expect(responses.get('one-style.css').fromCache()).toBe(true);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, didn't think of subscribing to the event later. Could be an issue when the responses map gets larger because of no filtering due to more resources being added. But I like this for the current solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note for anyone else who goes to look at the above code the second expectation should be toBe(false).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have made those changes now.
3247d00 to
eff7da3
Compare
|
@aslushnikov - is the appveyor continuous-integration required for this PR? I have had it passing before it just seems a bit flakey. I can rerun them if you think necessary. |
This change adds in the `Page.setCacheEnabled(enabled)` method to toggle ignoring cache for each request.
@andrewwwcollins appveyour is very flaky for us; this has nothing to do with your change. Thank you for you time. |
- Adding missing language tags to markdown code blocks. - Switching `npm` to `yarn` in README to be consistent with what repo is using locally/with travis. Removed unneeded and for yarn command per code review Also removing from travis and appveyor yarn invocations Fixed merge conflicts and yarn references Removed yarn.lock and added language to code fence Cheeky capital letter Touched up numbering (and also switched git email account due to CLA mis-match) feat(Page): add `setCacheEnabled(enabled)` to Page object (puppeteer#1609) This change adds in the `Page.setCacheEnabled(enabled)` method to toggle ignoring cache for each request. Fixes puppeteer#1556. docs(CONTRIBUTING): update contributing.md (puppeteer#1973)
Fixes: #1556
Implements
Page.disableCache(disabled)method.