Home Web Front-end JS Tutorial RemoveCookieWall, una extension de Firefox

RemoveCookieWall, una extension de Firefox

Sep 12, 2024 am 10:31 AM

RemoveCookieWall, una extension de Firefox

Are you fed up with the banner that has become fashionable on websites so that you accept third-party cookies or checkout? In this post I explain how I made (and published) a Firefox extension to avoid it on most sites

INFO

The code for this extension is published at https://github.com/jagedn/removecookiewall-addon and you can install it in Firefox (also on mobile) from https://addons.mozilla.org/es/firefox/addon/removecookiewall/

For a few months, and due to a European requirement (I think), most websites show you a banner the first time you access them that do not let you continue until you decide between:

  • I am going to place thousands of third-party cookies in your browser that will spy on what you browse

  • go to the checkout and pay me so I don't do it

Most of these libraries execute javascript as soon as the page is loaded that reads your cookies. If they see that you have not checked out, they show you an HTML dialog and block the body changing the style to "block" (or similar)

This dialog doesn't let you read what's underneath but...​ it's still a DOM element of the HTML, so, since browsers allow you to open a development console and inspect the HTML, I came up with the idea of ​​eliminating manually the dialog (you simply click on inspect, search in the HTML where it is defined and click on delete) and chimpón, the dialog disappears. Then I look for the "body" declaration and by double clicking on the style attribute I remove the property that blocks it and I can now scroll.

Little magic.

What is happening then? Well, the javascript code simply keeps waiting for a user event to arrive telling it which button you have pressed, but these buttons are no longer there, so it will never arrive and it will not install third-party cookies.

Ok, but what if I refresh the page? Well start again...​ so this is perfect for a new browser extension to do it for me.

RemoveCookieWall Extension

A Firefox extension, in short, is a reserved browser memory space where javascript code is executed that can dialogue with it.

It can (if the user grants permissions) inject code into the pages you visit, open tabs, close them, communicate with remote services,...

RemoveCookieWall is a Firefox extension that the "only" thing it needs is for the browser to inject a small javascript code into all the pages that the user visits.

This javascript, as the page has loaded, will inspect if there is a DOM element that matches any of the ones I have investigated that they are using. If it detects it, it will use standard Javascript functions to delete it.

As the banner can sometimes appear (milli)seconds after our code is executed, what the script does is repeat the search for a couple of seconds. After this time, if the banner has not appeared, the extension assumes that the page does not have a CookieeWall and ends

And this is all. All that remains is to package the code, add a Manifest file that indicates the permissions our extension requires and publish it in Firefox

Code

The JS code is basically:

var readyStateCheckInterval;
var counter = 0;

function sanitizeBody() {
    document.body.style.overflow = "unset"
    document.body.classList.remove('sxnlzit')
    document.body.classList.remove('didomi-popup-open')
    document.body.parentNode.classList.remove('sp-message-open')
}

function removeMe(element) {
    element.remove();
    sanitizeBody();
}

readyStateCheckInterval = setInterval(function() {
    if (document.readyState === "complete") {
        counter++;
        const removeParent = ['div.pmConsentWall']; //elpais
        [...removeParent].forEach(s => {
            var divs = document.body.querySelectorAll(s);
            [...divs].forEach(element => {
                removeMe(element.parentNode);
            });
        });
        const removeThis = [
            'div[data-nosnippet="data-nosnippet"]',
            '#mrf-popup',
            '#didomi-popup',
            '[id^="sp_message_container_"]',
            '#cl-consent',
            'dialog.cookie-policy'
        ];
        [...removeThis].forEach(s => {
            var divs = document.body.querySelectorAll(s);
            [...divs].forEach(element => {
                removeMe(element);
            });
        });
        if (counter > 30) {
            clearInterval(readyStateCheckInterval);
        }
    }
}, 100);
Copy after login

As soon as the code is injected into the page, an interval starts every 100 mili

The script looks to see if the document.body.querySelectorAll finds any element like #mrf-popup, #didomi-popup, etc. If it finds it, simply remove it with element.remove()

After a few attempts it ends up deleting the interval

Every extension must have a Manifest file. The one for this extension is simply:

{

    "description": "Remove CookieWall",
    "manifest_version": 2,
    "name": "RemoveCookieWall",
    "version": "0.11",
    "homepage_url": "https://github.com/jagedn/removecookiewall-addon",
    "icons": {
        "48": "icons/border-48.png"
    },
    "content_scripts": [{
        "matches": [
            "*://*/*"
        ],
        "js": ["removeCookieWall.js"]
    }],
    "browser_specific_settings": {
        "gecko": {
            "id": "remove-cookiewall@aguilera.soy"
        }
    }
}
Copy after login

As you see, content_scripts indicates that we want to inject the js into all pages. Other extensions can indicate only a site, others execute a javascript in the background, …

Build and publish

To publish in Firefox we simply have to provide a zip containing all the files required by the extension. To make it easy I have made a build.sh that simply runs the zip:

zip -r -FS ../remove-cookiewall.zip * --exclude '.git' --exclude 'build.sh'

Publishing an extension in Firefox has no complications and is free. The only thing that your extension has to pass an initial review that may take one (or several) days

The above is the detailed content of RemoveCookieWall, una extension de Firefox. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Zustand asynchronous operation: How to ensure the latest state obtained by useStore? Zustand asynchronous operation: How to ensure the latest state obtained by useStore? Apr 04, 2025 pm 02:09 PM

Data update problems in zustand asynchronous operations. When using the zustand state management library, you often encounter the problem of data updates that cause asynchronous operations to be untimely. �...

See all articles