chrome.devtools.network.getHAR() does not return all pages

1,461 views
Skip to first unread message

ak2614

unread,
Dec 18, 2013, 3:17:53 AM12/18/13
to google-chrome-...@googlegroups.com

I am developing a DevTools extension that needs to process the network requests made in the browser over multiple pages using the HAR data available through DevTools. 

On enabling "Preserve Log Upon Navigation" and browsing multiple pages, the HAR exported by the Network tab using "Copy all as HAR" has multiple "pages" and entries corresponding to all the pages navigated to (everything that is listed in the Network tab). I've got already some got some code that processes it. However, the HAR returned by chrome.devtools.network.getHAR() only has data for the last page opened, regardless of how many individual pages have been listed in the Network tab. 

The docs also suggest that the HAR should match what's in the Network tab. Are there some restrictions to this or could this be a bug?

There may be alternatives like the chrome.webRequest API or maybe using the onRequestFinished network event to track requests. But sticking to DevTools ties in well with the extension's purpose and getHAR() should have all that's required in one place.

Thanks!

Andrey Kosyakov

unread,
Dec 18, 2013, 3:29:09 AM12/18/13
to Google Chrome Developer Tools
Hi Abha,

chrome.devtools.network.getHAR() does not honor the state of Preserve Log upon Navigation button and will only return the log for the last page. This is the intended behavior, and the rationale is that we don't want extension behavior to depend on the user's configuration in this case. You can, however, obtain the entire list of resources by subscribing to chrome.devtools.network.onRequestFinished event -- you will get a HAR entry for each request. You will still need to call getHAR() first to get the requests that finished loading before your extension was loaded.

Best regards,
Andrey.



--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/912e0db3-d286-46df-82ae-3daf1f0acf3f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ak2614

unread,
Dec 23, 2013, 1:39:22 PM12/23/13
to google-chrome-...@googlegroups.com, ca...@chromium.org

Yeah, I see the rationale here. It makes sense to insulate the extension from user configuration, since, it may lead to something like a user pressing the Clear button in the Network tab causing getHAR() to be empty too. 

I'll make use of chrome.devtools.network.onRequestFinished. Thanks for the explanation.

Regarding the Request object that's passed to onRequestFinished, can getContent() for that request be called at any point in time later? For example, if the user has navigated to other pages in the mean time, would the content expire or does it actually get fetched (again) when called?

On Wednesday, December 18, 2013 3:29:09 AM UTC-5, Andrey Kosyakov wrote:
Hi Abha,

chrome.devtools.network.getHAR() does not honor the state of Preserve Log upon Navigation button and will only return the log for the last page. This is the intended behavior, and the rationale is that we don't want extension behavior to depend on the user's configuration in this case. You can, however, obtain the entire list of resources by subscribing to chrome.devtools.network.onRequestFinished event -- you will get a HAR entry for each request. You will still need to call getHAR() first to get the requests that finished loading before your extension was loaded.

Best regards,
Andrey.

On Wed, Dec 18, 2013 at 12:17 PM, ak2614 <abha.k...@gmail.com> wrote:

I am developing a DevTools extension that needs to process the network requests made in the browser over multiple pages using the HAR data available through DevTools. 

On enabling "Preserve Log Upon Navigation" and browsing multiple pages, the HAR exported by the Network tab using "Copy all as HAR" has multiple "pages" and entries corresponding to all the pages navigated to (everything that is listed in the Network tab). I've got already some got some code that processes it. However, the HAR returned by chrome.devtools.network.getHAR() only has data for the last page opened, regardless of how many individual pages have been listed in the Network tab. 

The docs also suggest that the HAR should match what's in the Network tab. Are there some restrictions to this or could this be a bug?

There may be alternatives like the chrome.webRequest API or maybe using the onRequestFinished network event to track requests. But sticking to DevTools ties in well with the extension's purpose and getHAR() should have all that's required in one place.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.

Andrey Kosyakov

unread,
Dec 24, 2013, 7:36:56 AM12/24/13
to Google Chrome Developer Tools
Hi Abha,

You can generally call request.getContent() at any time, but DevTools will never re-fetch resource content from the network, we will either return the content from in-memory cached or null if it got obliterated from the memory cache in renderer. The memory cache is likely to be cleared upon the navigation, as the navigation target may be loaded in a different renderer process. We try to avoid excessive memory consumption by the inspected page, so we may evict resources from in-memory cache. If you really need content, you should either fetch it with getContent as soon as possible or re-fetch them from the network with an XHR when getContent() fails.

Best regards,
Andrey.



To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/94600ad8-f861-4e89-acdf-9a6b4beb4f5d%40googlegroups.com.

ak2614

unread,
Dec 26, 2013, 11:09:45 AM12/26/13
to google-chrome-...@googlegroups.com, ca...@chromium.org

Thanks Andrey. This is great information.
Reply all
Reply to author
Forward
0 new messages