-
Notifications
You must be signed in to change notification settings - Fork 9.3k
feat(Response): add fromDiskCache/fromServiceWorker info #1601
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
|
I'm not able to run all the tests b/c of #1600. Any idea why Travis is unhappy? |
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.
If I understand it correctly, every response could be served either from network, disk cache or service worker. So it's never the case that both fromDiskCache and fromServiceWorker are true. Is this the case?
If so, I'd rather do a response.servedFrom() method that returns either network, diskcache or serviceworker.
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.
They can both be true at the same time. If you check a request against https://googlechrome.github.io/samples/service-worker/basic/, it shows both fromDiskCache and fromServiceWorker as true. From what I understand fromServiceWorker is when the request is served from the fetch event inside the web worker. But fromDiskCache will also return true if you return from the Cache API.
Hope I haven't misunderstood your question.
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.
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.
looks like response is being assigned to the scope but not used
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.
done. weird linting didnt catch this.
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.
page and browser are passed into the test:
async ({page, browser}) => {
// ..
});No need to create another one; reusing browser speeds up tests significantly
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 was doing that but it was causing other tests to fail: https://travis-ci.org/GoogleChrome/puppeteer/jobs/317396566#L556
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.
please don't use external URLs; we aim for the hermetic builds.
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 tried to use one-style.html for the test but it would require additions to sw.js and the test server doesn't support caching AFAIK.
What do you suggest for the server part?
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've added caching to the test server. Still seeing a lot of unrelated errors that I could use your help on. Not familiar enough with the worker and custom test server.
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 make them functions to unify our API
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.
done
|
Rebased. Still need guidance on what do about #1601 (comment). The added caching to the server causes unrelated tests to fail. Instead, we could go back to a well-known URL that has caching + sw. https://googlechrome.github.io/samples/service-worker/basic/index.html is our official service worker demo and won't be changing. |
|
I can also switch to |
- add browser caching to test server
|
rebased |
|
@ebidel let me introduce caching to the simple server so that this can be merged in. |
|
@ebidel the patch doesn't handle memory caching, and it's quite hard to predict if the response will be memory-cached or disk-cached. As far as I know the behavior is not spec'ed in chrome. I'd expose |
|
I don't mind changing the name but doesn't the protocol differentiate the two? The name and docs from |
|
@ebidel the protocol differentiates between the two; memory-cached responses are reported with |
|
What about this: const responsesFromMemCache = [];
page._client.on('Network.requestServedFromCache', result => {
responsesFromMemCache.push(result.requestId);
});
page._client.on('Network.responseReceived', result => {
const resp = result.response;
resp.fromMemoryCache = responsesFromMemCache.includes(result.requestId);
console.log(resp.url, resp.fromMemoryCache, resp.fromDiskCache, resp.fromServiceWorker);
});Screenshot is from testing on https://stackoverflow.com/questions/13140318/check-whether-network-response-is-coming-from-server-or-chrome-cache: Want to add |
It does. However, since response could be served either from memory or disk cache, a single |
|
Cool. I've changed the name.
Also removed my |
Yeah, let's add it - otherwise it's quite hard to test the
I'll upload implementation shortly |
|
LMK if that looks ok. |
lib/NetworkManager.js
Outdated
| this._fromMemCache = false; | ||
| } | ||
|
|
||
| _setFromMemoryCache(fromMemCache) { |
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.
nit: let's drop the method and reach into request right away
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.
done
lib/NetworkManager.js
Outdated
| _onRequestServedFromCache(event) { | ||
| const request = this._requestIdToRequest.get(event.requestId); | ||
| if (request) | ||
| request._setFromMemoryCache(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.
request._fromMemoryCache = 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.
done
lib/NetworkManager.js
Outdated
| for (const key of Object.keys(payload.headers)) | ||
| this._headers[key.toLowerCase()] = payload.headers[key]; | ||
|
|
||
| this._fromMemCache = 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.
nit: let's rename into this._fromMemoryCache
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.
done
|
@aslushnikov ready for your additions :p |
|
I wasn't able to push in this branch, so closing in favor of #1971. |
Fixes #1551
I tried to use
one-style.htmlfor the test but it would require additions to sw.js and the test server doesn't support caching AFAIK.