Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $replace and $$ rules partial support #864

Closed
ameshkov opened this issue Sep 28, 2017 · 7 comments
Closed

Add $replace and $$ rules partial support #864

ameshkov opened this issue Sep 28, 2017 · 7 comments
Assignees
Milestone

Comments

@ameshkov
Copy link
Member

ameshkov commented Sep 28, 2017

Firefox now supports filterResponseData which gives us the ability to filter HTML responses body:
https://blog.mozilla.org/addons/2017/09/28/webextensions-in-firefox-57/

Also, this question implies that the very same feature is available in Chrome:
https://support.mozilla.org/en-US/questions/1176377

function listener(details) {
 let filter = browser.webRequest.filterResponseData(details.requestId);
 let decoder = new TextDecoder("utf-8");
 let encoder = new TextEncoder();

 filter.ondata = event => {
    let str = decoder.decode(event.data, {stream: true});
    str = str.replace(/Example/g, 'WebExtension Example');
    filter.write(encoder.encode(str));
    filter.disconnect();
 }

 return {};
}

browser.webRequest.onBeforeRequest.addListener(
 listener,
 {urls: ["https://example.com/*"], types: ["main_frame"]},
 ["blocking"]
);

So, we can use it to implement partial support of $$ and $replace rules.

Applying $$ rules may be slow as we need to use DOMParser. To mitigate it we need to limit $$ rules to domain-specific rules only.

@ameshkov ameshkov added this to the 2.8 milestone Sep 28, 2017
@ameshkov
Copy link
Member Author

ameshkov commented Sep 28, 2017

I can't find it in Chromium's sources, though. So the use of it may be limited to Firefox only

@ghajini
Copy link

ghajini commented Oct 10, 2017

@ameshkov,
$$ rule -useful for browser extension users(there is limit I think $$) this is useful for longstanding instart logic crap...

@ameshkov
Copy link
Member Author

Both $$ and $replace are really useful and can help us. Unfortunately, in FF only

@ghajini
Copy link

ghajini commented Oct 10, 2017

Basically I was restricted from using adguard chrome browser extension becoz instart logic bypasses chrome extension due to large inline scripts....this work as per AdamWr in adguard for windows but not work in browser extension due to limited $$rule support.......

AdguardTeam/AdguardFilters#3844

@ameshkov
Copy link
Member Author

We've figured a way for FF, eventually we'll find a way for Chrome as well

@BooBerry
Copy link

I guess Edge and Safari are out in the cold then? =P

Great news, hopefully you guys will find a way for Chrome too. 👍

@zebrum
Copy link
Member

zebrum commented Dec 4, 2017

doesn't work

I've checked with this rules:

forum.ru-board.com$$table[width="95%"]
lenta.ru$$div[class="logo-wrap js-logo"]

@zebrum zebrum reopened this Dec 4, 2017
Mizzick added a commit that referenced this issue Dec 5, 2017
Mizzick pushed a commit that referenced this issue Dec 5, 2017
…ssues/864-fix-utf8 to master

* commit 'bff585d92d3b533f23e84a3ca320fb4b3b87b185':
  #864 fix tests
@vbagirov vbagirov closed this as completed Dec 5, 2017
adguard pushed a commit that referenced this issue May 5, 2021
Merge in EXTENSIONS/browser-extension from feature/AG-7953 to feature/AG-2737

* commit '4f1337f712bfb0a2b874ba3d7a1dcabee66f1edb':
  add findChunks test for escaped character
  improve findChunks and add tests for it
  use HighlightSearch for filter name displaying while searching
  add FilterTitle component for search highlight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants