仅在chrome开发工具中使用xhr请求创建har文件 [英] Create a har file with xhr request only in chrome dev tools
问题描述
是否只有在chrome开发工具中可以通过xhr
请求创建har
文件?
Is there a way to create a har
file with xhr
request only in chrome dev tools?
尽管我可以在开发工具中过滤请求,但是当我将其保存为har文件时,它包含所有请求.
Even though I can filter the requests in dev tools, when I save it as a har file, it contains all the requests.
如果dev devtools不支持该功能,是否还有其他方法可以实现?
If the dev devtools doesn't support that, is there a alternative way to do this?
推荐答案
似乎没有直接过滤请求的方法.我所做的就是创建包含所有请求的har
文件并过滤该文件,然后在删除不需要的请求后再次保存它.
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.
在har
文件内的内容中有一个名为entries
的条目.它包含我们在数组中发送的所有请求.我得到了har
文件的内容,并使用JSONPath
表达式对其进行了过滤.
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.
关于JSONPath ,要过滤的表达式application/json
类型:$..entries[?(@.response.content.mimeType == "application/json")]
Expression to filter application/json
types : $..entries[?(@.response.content.mimeType == "application/json")]
之后,我将条目数组替换为在har
文件中过滤的条目数组,然后再次保存.这样,您可以获取带有过滤的请求的har
文件.使用相关的JSONPath
表达式
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
这篇关于仅在chrome开发工具中使用xhr请求创建har文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!