Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Add AdGuard-trusted scriptlets to replace the old JS rules

Open ameshkov opened this issue 5 years ago • 12 comments

https://github.com/AdguardTeam/AdguardFilters/blob/master/AnnoyancesFilter/sections/cookies_specific.txt#L4707

There are tons of JS rules in the Annoyances filter that deal with cookie consent screens.

We should find a way to use scriptlets for that. We may need to introduce a "trusted" type of scriptlets for that, allowed to the user filter and our filter lists only, i.e. trustLevel: full.

  • [ ] click() an element: over 180 rules using this https://github.com/AdguardTeam/Scriptlets/issues/23
  • [ ] localStorage.setItem: over 200 rules using localStorage.setItem
  • [ ] Setting cookies: over 200 rules using document.cookie.
  • [ ] setting HTML elements attributes, example: https://github.com/AdguardTeam/AdguardFilters/pull/69608
  • [ ] creating bait elements
  • [ ] https://github.com/AdguardTeam/Scriptlets/issues/137
  • [ ] https://github.com/AdguardTeam/Scriptlets/issues/196
  • [ ] https://github.com/AdguardTeam/Scriptlets/issues/202

ameshkov avatar Dec 02 '20 08:12 ameshkov

https://github.com/AdguardTeam/AdguardFilters/blob/70ee34ef97c141408bbe45f646a7f4354cd3e8cb/AnnoyancesFilter/sections/cookies_specific.txt#L4704-L5073 - daily file have new lines above 4707

krystian3w avatar Dec 08 '20 06:12 krystian3w

I'll keep a checklist with categorized ideas in the top comment.

But I'll need examples for every kind of it.

ameshkov avatar Dec 08 '20 20:12 ameshkov

I suggest to mark new AdGuard-trusted scriptlets with a prefix ag- or agtrusted- so final names will be like ag-set-cookie-free or agtrusted-click-element. they also should have no aliases to emphasize that there are no analogs and as a result to prevent converting and supporting in third-party filters lists

slavaleleka avatar Dec 22 '20 11:12 slavaleleka

Let's go with trusted-, it's a bit longer, but the meaning is clearer.

ameshkov avatar Dec 22 '20 12:12 ameshkov

Regarding creating bait elements, I think that at the moment this website might be a good example - https://github.com/AdguardTeam/AdguardFilters/issues/75764 Their script is obfuscated, but if I understand correctly, they are doing something like:

if ( document.getElementsByClassName("mghead").length < 1 ) {
    console.log("adblock detected");
}

so creating element with class mghead fixes anti-adblock.

AdamWr avatar Feb 25 '21 12:02 AdamWr

Can you please add sessionStorage along with it? #118

bestpika avatar Mar 09 '21 06:03 bestpika

Adblock Plus has a snippet simulate-event-poc which is related to click-an-element subtask https://github.com/abp-filters/abp-filters-anti-cv/commit/246d6ae5358b5da6ec14c06c6169582e77ac20f6

slavaleleka avatar Jan 17 '22 15:01 slavaleleka

@slavaleleka this one is interesting, but it should definitely be limited to trusted lists only.

ameshkov avatar Jan 18 '22 08:01 ameshkov

ABP still support all snippets form only anti-cv file or from own addons settings in place "my added rules".

So no need fastly write system for privileges (can wait as mark use other snippet as safe loaded form any filter list file).

krystian3w avatar Jan 18 '22 12:01 krystian3w

We're adding support for "trusted" scriptlets to CoreLibs: https://github.com/AdguardTeam/CoreLibs/issues/1612

Once it's added, we should start working on the new scriptlets.

ameshkov avatar Mar 16 '22 08:03 ameshkov

I suppose all world wait for official syntax.

krystian3w avatar Mar 16 '22 16:03 krystian3w

Regarding setting HTML elements attributes, it would be useful if we could also set attribute by getting one of the current attributes from element.

For example, here - https://hdfilmifullizle.com/13-mezar-izle This website stores video source in data-sonrayukle attribute (and add src attribute after an ad is finished), so that would be nice, if we could also in this scriptlet get attribute from an element and add src attribute with that attribute.

Screenshot

image

AdamWr avatar Aug 22 '22 15:08 AdamWr

These were implemented in 1.7.3 release:

  • trusted-click-element
  • trusted-replace-xhr-response
  • trusted-replace-fetch-response
  • trusted-set-local-storage-item
  • trusted-set-cookie

The rest will be added in 1.8

stanislav-atr avatar Nov 21 '22 17:11 stanislav-atr

issues for the rest trusted scriptlets

  • https://github.com/AdguardTeam/Scriptlets/issues/137
  • https://github.com/AdguardTeam/Scriptlets/issues/278
  • https://github.com/AdguardTeam/Scriptlets/issues/281

slavaleleka avatar Jan 09 '23 17:01 slavaleleka

Regarding setting HTML elements attributes, it would be useful if we could also set attribute by getting one of the current attributes from element.

With this we can replace script rules for https://github.com/AdguardTeam/AdguardFilters/issues/132525, https://github.com/AdguardTeam/AdguardFilters/issues/132814, https://github.com/AdguardTeam/AdguardFilters/issues/135699 Maybe should add TODO comment.

Yuki2718 avatar Jan 27 '23 12:01 Yuki2718