cavi-au / Consent-O-Matic

Browser extension that automatically fills out cookie popups based on your preferences
Other
2.53k stars 123 forks source link

Tutorial for creating rules? #436

Closed jmbreuer closed 4 months ago

jmbreuer commented 4 months ago

I've looked at the docs and a clearly outlined process how to turn a page's cookie banner into a (working) CoM ruleset still quite eludes me.

The cookie dialogs on Serverfault et al seem fairly full featured and not covered by CoM yet, maybe someone could put together an example where/how to choose & find the various rule elements to create a full-featured rule working for this site.

(Could the rule editor possibly be upgraded to directly allow picking elements on a page, for example? Possibly with a second step then to choose which criteria of the picked element to use in the rule.)

jmbreuer commented 4 months ago

... how would I formulate/use the rule editor to specify the absence of style="visibility: hidden" / display: none for the showingMatcher, for a start?

jmbreuer commented 4 months ago

... I've taken another stab at ez-cmpv2 on this page

I have these rules so far:

{
    "$schema": "https://raw.githubusercontent.com/cavi-au/Consent-O-Matic/master/rules.schema.json",
    "ez-cmpv2": {
        "detectors": [
            {
                "presentMatcher": [
                    {
                        "type": "css",
                        "target": {
                            "selector": "#ez-cmpv2-container"
                        }
                    }
                ]
            }
        ],
        "methods": [
            {
                "name": "HIDE_CMP"
            },
            {
                "action": {
                    "type": "click",
                    "target": {
                        "selector": "#ez-manage-settings"
                    }
                },
                "name": "OPEN_OPTIONS"
            },
            {
                "action": {
                    "type": "list",
                    "actions": [
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#1"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#1"
                                        }
                                    },
                                    "type": "D"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#10"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#10"
                                        }
                                    },
                                    "type": "X"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#10"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#10"
                                        }
                                    },
                                    "type": "X"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#11"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#11"
                                        }
                                    },
                                    "type": "E"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#11"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#11"
                                        }
                                    },
                                    "type": "E"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#2"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#2"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#2"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#2"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#3"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#3"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#4"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#4"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#5"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#5"
                                        }
                                    },
                                    "type": "E"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#6"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#6"
                                        }
                                    },
                                    "type": "E"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#7"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#7"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#7"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#7"
                                        }
                                    },
                                    "type": "F"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#8"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#8"
                                        }
                                    },
                                    "type": "B"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#8"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#8"
                                        }
                                    },
                                    "type": "B"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#9"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-li-checkbox#9"
                                        }
                                    },
                                    "type": "X"
                                }
                            ]
                        },
                        {
                            "type": "consent",
                            "consents": [
                                {
                                    "matcher": {
                                        "type": "checkbox",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#9"
                                        }
                                    },
                                    "toggleAction": {
                                        "type": "click",
                                        "target": {
                                            "selector": ".ez-cmp-purpose-consent-checkbox#9"
                                        }
                                    },
                                    "type": "X"
                                }
                            ]
                        }
                    ]
                },
                "name": "DO_CONSENT"
            },
            {
                "action": {
                    "type": "click",
                    "target": {
                        "selector": "#ez-save-settings"
                    }
                },
                "name": "SAVE_CONSENT"
            },
            {
                "name": "UTILITY"
            }
        ]
    }
}

Automating the click on "Manage Settings" to open the detail pane works, but handling the checkboxes (apparently) doesn't.

Any hint how I would change what I have to make it work (better)?

jmbreuer commented 4 months ago

OK I found one issue, element#11 (or whatever) would (obviously) try to match by its id attribute, not data-id as the page actually uses - didn't read that carefully enough, it seems. So, I should rather use ...[data-id='whatever']

Using the DevTools Highlighter I can verify that e.g. .ez-cmp-li-checkbox[data-id='10'] does the right thing selecting the first pre-checked legitimate interest box, but a ClickAction on the same selector does not seem to un-check it. ...

jmbreuer commented 4 months ago

I also found out how I can use the extension to load existing rules, e.g. ez-cookie into the rule editor. It seems to follow a quite different structure though, using loops and text matches rather than directly selecting specific elements.

Again, this is where a tutorial outlining 'intended use', 'best practices' and so on would come in great.

jmbreuer commented 4 months ago

Aand I finally found the Dev flags - skipping submit, debugLog, paintMatchers etc.

Unfortunately, with those turned on the page behaves differently for me: The CMP overlay only shows up for the first time after (as can be seen while watching the JS Console) all the CoM processing has run, and it has given up with "No CMP detected in 5 seconds, stopping engine...".

Which might also explain why the existing ez-cookie rule only occasionally seems to match on this page, and mostly not. Is there an easy way to change this ordering / the 5 second timeout?

jmbreuer commented 4 months ago

Last but not least, how can I override a rule from the standard set to figure out how to 'fix' it as a custom one? Apparently, ez-cookie matches (sometimes?) on that page, it doesn't correctly process and my own ez-cmpv2 rule apparently isn't even considered in that case.(?)

AUToelboell commented 4 months ago

Hi, thank you for your interest in the project. No we don't have any guide on how to create a rule. We have documentation in the read me. The reason for not having a guideline, and the rules being so different, as you mention, is due to the websites being so different. Sometimes the only thing separating 2 consent check boxes, can be the text in a parent div, in other cases they have separate ID's. But we will consider if making guidelines and guides, will makes sense, with the project being in this state.

We don't have a way to turn of a rule. But if the name of a custom rule is the exact same as the name of the rule from the plugin source. It Will only use the custom rule. Which eliminates your problem, since I strongly recommend changing an existing rule, which works most of the time. I have identified the problem, which is caused by opening the choice takes longer than searching the the selector. The problem should be fixed by now.

You can't change this with a rule, "No CMP detected in 5 seconds, stopping engine...", and it is now necessary, i have only encountered one, website where it was a problem, and the CMP deterministically showed up after around 7seconds. In any other case it has been a broken rule.

jmbreuer commented 4 months ago

Thank you! I can confirm that the ez-cookie page now works well for me, too; as does the serverfault one.