Any better way to disable all the cookie consent checkboxes / sliders?

51 views Asked by At

From Europe, this page https://www.britannica.com/place/British-Virgin-Islands will show a cookie consent dialog.

To quickly deny all cookies, one has to select "Manage Settings" and then, Vendors. All lines seem to be deactivated, however, at a closer inspection, the lines containing an "i" tooltip will have a "legitimate interest" active within them.

For the below script to work, since the cookie dialog is an iframe, one first has to inspect anything within the iframe, when the vendors are shown. After that, the below code can be copied into the console and run via pressing ENTER.

NOTE: some of the HTML elements in the iframe may change over time, and the querySelector's may need updating.

tooltips = document.querySelectorAll('div[_ngcontent-ng-c2192111456][role="tooltip"]');
end = tooltips.length;
stopAction = false;

for ( let i=0; i<end && !stopAction; i++ ) {
    
    console.log("Progress: " + i + " / " + (end-1));
    
    // as soon as the loop finishes and moves on to the next cycle, the tooltips variable
    // looses the references? so, initiate it again every time
    tooltips = document.querySelectorAll('div[_ngcontent-ng-c2192111456][role="tooltip"]');
    row = tooltips[i].parentNode;
    
    if ( (tooltips.length>0) && tooltips[i] && row ) {
        row.click();
        
        // wait 100ms for the page elements to "surely" be present?
        await new Promise(resolve => setTimeout(resolve, 100));
        
        switchBox = document.querySelector('span[role="checkbox"][aria-checked="true"]');
        
        if ( switchBox ) {
            switchBox.click();

            //wait 150 ms to see the checkbox/slider animation
            await new Promise(resolve => setTimeout(resolve, 150));
        }
        
        backButton = document.querySelector('span[_ngcontent-ng-c2083334920]');
        
        if ( backButton ) {
            backButton.click();
            
            // wait 300 ms so that the IFrame's content get's changed?
            await new Promise(resolve => setTimeout(resolve, 300));
        }
    } else {
        console.log("row not found --> " + i);
    }
}

If one does not inspect an element on the Vendor page in the cookie dialog, the querySelectors won't return the expected elements (from browser consoles).

0

There are 0 answers