Create a har file with xhr request only in chrome dev tools
Asked Answered
D

2

9

Is there a way to create a har file with xhr request only in chrome dev tools?

Even though I can filter the requests in dev tools, when I save it as a har file, it contains all the requests.

If the dev devtools doesn't support that, is there a alternative way to do this?

Donte answered 10/10, 2019 at 14:53 Comment(0)
D
8

Seems like there is no direct way to filter the requests. What I did was, creating the har file with all the requests and filter that file, then save it again after removing unwanted requests.

There is a entry called entries in the content inside har file. It contains all the requests we have sent in an array. I got the har file content and filtered it using JSONPath expressions.

About JSONPath, JSONPAth evaluator

Expression to filter application/json types : $..entries[?(@.response.content.mimeType == "application/json")]

After that I have replaced the entries array with the one I have filtered in the har file and saved it again. This way you can get a har file with filtered requests. Same way you can filter XHR or any other types using the relevant JSONPath expression

Donte answered 13/10, 2019 at 11:8 Comment(2)
Could you please share code, how can I extract XHR call only from .har fileBertrando
Try this, $..entries[?(@._resourceType == "xhr")]Donte
P
0

I recently came across this same issue while doing some research for mocking network calls in playwright. It does provide ability to record only the call you are interested in. Here is the link: https://playwright.dev/docs/network#recording-har-with-cli

Pagurian answered 24/9, 2022 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.