Chrome 开发工具: 有什么方法可以排除 URL 与正则表达式匹配的请求?

不幸的是,在最新版本的 Chrome 中,负网络过滤器不再起作用了。我使用这个过滤器来排除包含特定字符串的每个 http 调用。我在 Chrome 开发工具论坛上问了一个解决方案,但是没有人回答。

因此,我想知道是否有一种方法可以用正则表达式语法解决这个问题(例如,排除包含字符串“ loadMess”的每个调用)。

36644 次浏览

Update (2018):

This is an update to my old answer to clarify that both bugs have been fixed for some time now.

  1. Negate or exclude filtering is working as expected now. That means you can filter request paths with my.com/path (show requests matching this), or -my.com/path (show requests not matching this).

  2. The regex solution also works after my PR fix made it in production. That means you can also filter with /my.com.path/ and /^((?!my.com/path).)*$/, which will achieve the same result.

I have left the old answer here for reference, and it also explains the negative lookup solution.


The pre-defined negative filters do work, but it doesn't currently allow you to do NOT filters on the names in Chrome stable, only CONTAINS. This is a bug that has been fixed in Chrome Canary.

Once the change has been pushed to Chrome stable, you should be able to do loadMess to filter only for that name, and -loadMess to filter out that name and leave the rest, as it was previously.

Negative Filter

Workaround: Regex for matching a string not containing a string

^((?!YOUR_STRING).)*$

Example:

^((?!loadMess).)*$

Explanation:

  • ^ - Start of string

  • (?!loadMess) - Negative lookahead (at this cursor, do not match the next bit, without capturing)

  • . - Match any character (except line breaks)

  • ()* - 0 or more of the preceeding group

  • $ - End of string

Update (2016):

I discovered that there is actually a bug with how DevTools deals with Regex in the Network panel. This means the workaround above doesn't work, despite it being valid.

The Network panel filters on Name and Path (as discovered from the source code), but it does two tests that are OR'ed. In the case above, if you have loadMess in the Name, but not in the Path (e.g. not the domain or directory), it's going to match on either. To clarify, true || false === true, which means it will only filter out loadMess if it's found in both the Name and Path.

I have created an issue in Chromium and have subsequently pushed a fix to be reviewed. This has subsequently been merged.

Chrome broswer dev tools support regrex filter not very well.
When I want to hide some requests, it does not work as showed above. But you can use -hide1 -hide2 to hide the request you want.
Just leave a space between the conditions, and this does not match the regrex, I guess it may use string match other than regrex in principle

This is answered here - for latest Chrome 58.0.3029.110 (Official Build) (64-bit) https://stackoverflow.com/a/27770139/4772631

E.g.: If I want to exclude all gifs then just type -gif Here is a short example

On latest chrome version (62) you have to use :

-mime-type:image/gif

Negative lookahead is recommended everywhere, but it does not work.

Instead, "-myregex" does work for me. Like this: -/(Violation|HMR)/.

Filtering multiple different urls

You can negate symbol for filtering the network call. Eg: -lab.com would filter lab.com urls.

But for filtering multiple urls you can use the | symbol in the regex Eg: -/lab.com|mini.com/ This will filter lab.com and mini.com as well you can use it to filter many different websites or urls.