Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome dev tools: any way to exclude requests whose URL matches a regex?

Unfortunately in the last versions of Chrome the negative network filter doesn't work anymore. I used this filter in order to exclude each http call containing a particular string. I asked a solution in Chrome dev tool forum but at the moment nobody answered.

So I would like to know if there is a way to resolve this problem (and exclude for example each call containing the string 'loadMess') with regex syntax.

like image 282
suikoy Avatar asked Jul 22 '16 11:07

suikoy


People also ask

How do I block URL requests?

Right-click on the request in the Network panel and select Block Request URL. A new Request blocking tab pops up in the Drawer, which lets you manage blocked requests.

How do I block chrome requests?

There is a simple trick I use. Pressing F5 while in the tab immediately followed by ESC. XHR requests still active by chrome are canceled before the new answer is loaded.

How do I hide a tab request on a network?

Unfortunately for you, there's no way to hide network requests from Chrome Network Log. Even if you could, it'd be still possible to use network analyzer tools such as Fiddler and Wireshark to log all the traffic between your computer and the Internet.


1 Answers

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.

like image 153
Gideon Pyzer Avatar answered Oct 18 '22 09:10

Gideon Pyzer