问题
I want to filter Chrome DevTool's network panel by the method property and text in the URL. For example, if I am searching for the text chromequestion in the URL and only HTTP GET requests (ignore PUT, POST, DELETE, etc).
I am able to filter by text or by method:
I am not able to combine the filter to search by both text and method:
I read the documentation at https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#filters and I am able to filter by multiple properties (.e.g, domain:*.com method:GET). However, I am unable to filter by text and property (e.g., method:GET chromequestion).
回答1:
Unfortunately, it's not possible to do this currently. I played around in DevTools originally, but couldn't find a way. I later had a look into how the filtering was implemented, and can confirm there's a limitation preventing you from mixing the pre-defined filters and text filters.
Implementation details
This is a bit long but I thought it might be interesting for some to see how it's implemented. I will probably look into improving the implementation, either myself or I'll log it because it's limited.
There's a _parseFilterQuery
function that parses the input field and categorises the entries into two arrays. The first is called filters
, and it's the pre-defined filtering options, such as method:GET
etc. The second is a text
array filter, split up by spaces. The parser determines the difference fairly naively, by checking for the occurrence of :
, and -
at the start (for negation).
Scenario 1
You only input a pre-defined filter, or multiple filters. For each filter, the specific filter function, which looks at the different properties of the request object, is pushed to a network module filters array (this._filters
). Later on, for each request, the function is called on it, and a match returns true
, otherwise false
. This will determine whether the request is shown. There's obviously a requirement for ALL filters to return true
for the row to show.
Scenario 2
This is the interesting one, where you input both a pre-defined filter and a bit of text. This covers the Stack Overflow question. The _parseFilterQuery
function looks at the text filters first, before the pre-defined ones. In Scenario 1, this was empty, so it was skipped.
We pass each text word to the _createTextFilter
, and push each of the resulting filters to the network module filters array. However, the implementation of this is questionable. The only time the actual word passed in is used is to check whether its a negation filter for a bit of text. If the first character is -
, it means the user doesn't want to see a request with the following word in the name. For example -icon
means don't show any request with that in the name/page. If there is no negation, it simply returns the WHOLE input text as a regular expression, NOT the word passed in. In my case, it returns /method:GET icon/i
.
The pre-defined filters are looked at next. In this case, method:GET
is pushed.
Finally, it loops over the requests calling each filter on it. However, since the first filter is /method:GET icon/i
, it makes ALL other filters redundant because it will NEVER pass. The text filters only apply to name and path, so method:GET
in a text filter will be invalid.
来源:https://stackoverflow.com/questions/42008959/how-to-filter-by-both-text-and-property-in-chrome-devtools-network-panel