cyrus-and / chrome-har-capturer

Capture HAR files from a Chrome instance
MIT License
530 stars 90 forks source link

Is the cache cleaned for each visit? #57

Closed marty90 closed 6 years ago

marty90 commented 6 years ago

Ciao!

I've a quick question. If I run multiple times chrome-har-capturer without quitting Chrome between one visit and another, is the cache/profile cleaned? In other words, does each visit use a clean Chrome profile?

Thank You Martino

cyrus-and commented 6 years ago

It does not use a clean Chrome profile, in fact it uses whatever you provide since Chrome must be already started in order to run chrome-har-capturer.

But each URL is loaded in its own browser context:

Similar to an incognito profile but you can have more than one.

Thus both data and DNS (hopefully) caches should be flushed every time.

marty90 commented 6 years ago

Thank you for the quick answer. Is there a workaround to prevent this behavior? E.g., simulate a "second visit" of a web page, where most objects are already in the browser cache.

cyrus-and commented 6 years ago

I could add an option to use a single context across all the page loads, what do you think?

marty90 commented 6 years ago

It would be great! A lot of performance studies focus on the behavior of caches and cached objects!

cyrus-and commented 6 years ago

It should work, give it a spin.

marty90 commented 6 years ago

Cool! Thank You. It appears to work! Unfortunately the HAR file reports the entry also for objects coming from the cache. In other words, objects are correctly cached, but the HAR reports them. And it is impossible to distinguish an object coming from the network or from the cache. (I only noticed that the Date HTTP response header is some minutes before the visit to the page, and, thus, was for sure coming from cache)

However, I think it would be easy to implement as the Response struct from Chrome has a fromDiskCache boolean field. One could add this information in the cache field of the HAR entry, or create a new _fromDiskCache.

cyrus-and commented 6 years ago

Yes of course! I thought I added such commit instead I just stashed the change for whatever reason...

marty90 commented 6 years ago

It works perfectly :) Thank you !