cyrus-and / chrome-har-capturer

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

404 responses for javascript and stylesheets are not capturered #52

Closed lht closed 7 years ago

lht commented 7 years ago

The capturer seems to missing nonexisting javascript and stylesheet resources. For example, capture below page only captured root document and the photo.jpg. (Both requests for photo.jpg and missing.js returns 404).

<html>
  <body>
  hello,world
  <img src="photo.jpg"/>
  <script src="missing.js"></script>
  </body>
</html>

Comparing with saving HAR from chrome inspector, 3 entries are captured.

Upon further investigation, I found Chrome sends LoadingFailed events for Javascript and CSS resources, but LoadingFinished events for images. And the following change works for me.

diff --git a/lib/har.js b/lib/har.js
index df4f397..d3cd924 100644
--- a/lib/har.js
+++ b/lib/har.js
@@ -57,7 +57,7 @@ function parsePage(pageId, page) {

 function parseEntry(pageref, entry) {
     // skip requests without response (requestParams is always present)
-    if (!entry.responseParams || !entry.responseFinishedS) {
+    if (!entry.responseParams) {
         return null;
     }
     // skip entries without timing information (doc says optional)
cyrus-and commented 7 years ago

OK it seems that Chrome issues a Network.loadingFailed for CSS and JavaScript objects (at least), while a proper Network.loadingFinished for images, that is the web server response message is returned for images but not for CSS or JavaScript requests.

cyrus-and commented 7 years ago

It should be fixed now, please give it a try.

Thanks for reporting.