autoconsent icon indicating copy to clipboard operation
autoconsent copied to clipboard

Feature Proposal: Adblocker filter like syntax for AutoCMP

Open seia-soto opened this issue 1 year ago • 0 comments

Summary

Having adblocker-like syntax let you:

  • have better rule quality by filling missing fields in JSON definition in the rule creation step
  • create and manage the rules faster by having single file containing simple rules
  • publish rules easily to online

This system is opt-in and doesn't disturb current workflow in autoconsent. A dedicated project can be created to manage new syntax and transform the syntax into the current structure of autoconsent.

Please visit the following link for the quick view of suggested syntax.

  • https://github.com/seia-soto/filters2autoconsent/blob/master/src/parser/index.test.ts

The Syntax

domain.tld##selector[$option1][,option2=value][, ...]
-selector:action(args)
[-selector:action(args):chainedAction(args)]
[-...]
+selector:action(args)
[+selector:action(args):chainedAction(args)]
[+...]

Examples

The examples below are not fully implemented yet. They're likely to be changed in future.

Basic opt-in and opt-out

domain.tld##detectionSelector$cosmetic
-div#optout:wait(_: 500):click()
+div#optin:waitForVisible():click()

This is equivalent to the following JSON rule:

{
  "name": "domain.tld",
  "cosmetic": true,
  "runContext": {"urlPattern": "^https://(www\\.)?domain\\.tld/"},
  "detectCmp": [{ "exists": "detectionSelector" }],
  "detectPopup": [{ "visible": "detectionSelector" }],
  "optOut": [{ "wait": 500 }, { "click": "div#optout" }],
  "optIn": [{ "waitForVisible": "div#optin" }, { "click": "div#optin" }]
}

Chain multiple opt-in and opt-out actions

domain.tld###popup$cosmetic,name=sample
-div#showAllOptions:waitForVisible(timeout: 1000, check: all)
-div#optout:wait(_: 500):click()
+div#optin:click()

This is equivalent to the following JSON rule:

{
  "name": "sample",
  "cosmetic": true,
  "runContext": {"urlPattern": "^https://(www\\.)?domain\\.tld/"},
  "detectCmp": [{ "exists": "detectionSelector" }],
  "detectPopup": [{ "visible": "detectionSelector" }],
  "optOut": [{ "waitForVisible": "div#showAllOptions", "timeout": 1000, "check": "all" }, { "wait": 500 }, { "click": "div#optout" }],
  "optIn": [{ "click": "div#optin" }]
}

Conditionals

domain.tld###popup$cosmetic
-div#version1:if():exists()
-div#version1.optout:then():click()
-div#version2.optout:else():click()
+div#optin:click()

This is equivalent to the following JSON rule:

{
  "name": "domain.tld",
  "cosmetic": true,
  "runContext": {"urlPattern": "^https://(www\\.)?domain\\.tld/"},
  "detectCmp": [{ "exists": "detectionSelector" }],
  "detectPopup": [{ "visible": "detectionSelector" }],
  "optOut": [{ "if": { "exists": "div#version1" }, "then": [{ "click": "div#version1.optout" }], "else": [{ "click": "div#version2.optout" }] }],
  "optIn": [{ "click": "div#optin" }]
}

Drawbacks

  • Having multiple files is a better way to provide intuitive transparency.
  • Conditional syntaxes are not intuitive to write in current format.

seia-soto avatar Jan 04 '24 05:01 seia-soto