-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement network filter option
replace=
Reference documentation: https://adguard.com/kb/general/ad-filtering/create-own-filters/#replace-modifier This is a network filter option which can only be loaded from a trusted source. Since this filter is about modifying the response body, it currently only works in Firefox. As discussed with filter list maintainers.
- Loading branch information
Showing
7 changed files
with
537 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filters with simple regex are shown as invalid -
||example.org^$replace=/^uBlockOrigin$/i
but complex regex are shown valid -
||example.org^$replace=/(<VAST[\s\S]*?>)[\s\S]*<\/VAST>/\$1<\/VAST>/i
a limitation ?
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the "replacement" part?
Try
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, didn't realise replacement was compulsory for removal, thanks.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gorhill Is this only for replacing content in page source code but it cannot replace content in external scripts the page loads?
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation linked in the commit says:
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
.m3u8
file an object or a text response ?7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You tell me. If you want me to look into it, having a URL which I can readily paste in the address bar would be nice.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource response content-type must start with
text/
or be one ofapplication/javascript
,application/json
,application/xml
,application/xhtml+xml
,Is the change visible in dev tools debugger [edit: or it was "Network" tab where it does not show even now?]? If it is, it did not work for me with this commit on
application/javascript
files on AG doc page. Will test more recent version.It's working in 1.53.1b5, but no way to preview the effect in dev tools. If you omit the type, you can open in tab, and the changes are visible there. Nightly 121.0a1.
Dev tools debugger shows the change.
More types added later in ae24032
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I knew, we wouldn't be having this conversation.
No readily available with me. Take twitch for example.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's matter of opening the browser dev tools, then Network pane, then select one of those
m3u8
resource, and look-up content type.Now with that repro case in mind, I just did the described steps above, and I get
application/vnd.apple.mpegurl
. Looking at the content, it appears to be text. So I will addapplication/vnd.apple.mpegurl
as a valid target for response filtering.7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gwarser response content type is
application/vnd.apple.mpegurl
, so no chance huh ?7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you meant that. That I know.
great, thanks!!
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned twitch because of uBlockOrigin/uBlock-issues#2758, and now it seems
$replace
remains the only possibility.7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in https://github.com/gorhill/uBlock/releases/tag/1.53.1b6
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why I cannot replace text
loadChartbeat
withtest
?Page:
tivi.fi
Filter:
||tivi.fi^$replace=/loadChartbeat/test/
That string in the page source code.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tivi.fi##^script
does not work. ?7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true also.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a mistake, there was an extraneous
j += 1
left in there. This will be fixed in next build.7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That fixed it.
However I found a new link where some texts can't be replaced.
https://www.is.fi/seksi-parisuhde/art-2000008547493.html
Replace text
authenticated
withfree
in the page source code.||is.fi^$replace=/authenticated/free/
Out of 13 instances, only one is replaced, 12 aren't.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use regex flags.
g
perhaps?This works:
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was it. Now it works.
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this url?:
https://app-conf.almamedia.net/v3/conf.json
Trying to replace
global
withtest
but doesn't work.||app-conf.almamedia.net^$replace=/global/test/
7c3e060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Content type is
application/octet-stream
, so this can't go through a filterer which can just handle text-based content.