Generate HAR entries for requests made with node-fetch
MIT License
lookup
, connect
, secureConnect
) are now attached with once
and explicitly removed on request finish
. This fixes listeners from sticking around on sockets that end up being reused (for example, with agentkeepalive’s socket pooling._resourceType
field to fetch
so that requests are categorized under XHR/Fetch in common HAR viewers (like Chrome or Firefox’s Network tab).URL.createObjectURL
to generate the HAR download link in the Next.js demo. This is preferable because it allows the data to be of any size.Custom agents! If you pass a custom agent
to fetch
(as supported by node-fetch
) it will be instrumented with HAR tracking behavior. This allows you to use helpers like agentkeepalive.
If you are using the custom agent outside of withHar
contexts as well, this instrumentation should have no adverse effects and will be disabled unless invoked by withHar
specifically (since it adds a special header).
withHar
are now shared globally, instead of created for each withHar
instance.compression
field.Buffer.byteLength
instead of string length
where possible.process.hrtime
.send
duration by listening for the ClientRequest’s finish
event. In practice, most of this time is actually going to be attributable to DNS/connect/SSL/etc. but it’s better than nothing for now.node-fetch
where the constructor of the returned response
is not Response
, but rather a different Body
class that does not set the same properties. This caused our cloned response instance to not have a headers
property. Now, we check the input Fetch instance for a Response
property (like node-fetch
does) or try to get it from global
(like isomorphic-fetch
does) before falling back to response.constructor
. To fully override the class (for more complicated scenarios), use the new Response
option to withHar
.node-fetch
, isomorphic-fetch
, and isomorphic-unfetch
are tested. Even though they all use node-fetch
, isomorphic-fetch
uses an old version, and we may need to test additional integration points (like what properties exist on the default export).withHar
, or individual fetch
calls, can specify a custom page reference using the harPageRef
option.