A minimal Chrome extension that permanently hides a specific DOM element on any website — identified by a css selector you provide.
Some websites detect ad-blockers and overlay a blocking <div> (or similar element) over the page, prompting you to disable your ad-blocker. This extension lets you target that exact element by its css selector and remove it from view as soon as the DOM is ready — without touching anything else on the page.
Originally built for investing.com, using the selector #__next > div:last-of-type.
- Each rule is stored per domain using
chrome.storage.local. - Storage keys follow the prefix
specrule:. - On every page load, the extension looks for the first element matching the saved selector and sets
display: none !importanton it. - A
MutationObserverwatches the DOM for up to 15 seconds after load, so late-injected overlays (popups added after the initial render) are caught as well. - Once the element is found and hidden, the observer stops immediately.
- Open
chrome://extensions - Enable Developer mode (top-right toggle)
- Click Load unpacked
- Select this folder
- Navigate to the site where you want to hide an element.
- Click the extension icon in the toolbar.
- Enter the css selector for the element you want to hide.
- Click Save (or press
Enter).
The rule takes effect immediately on the active tab and on every subsequent visit to that domain.
To remove a rule, open the popup on that domain, clear the selector field, and save an empty value — or manage entries directly via chrome.storage.local in DevTools.
The input accepts any valid querySelector expression:
| Selector | What it targets |
|---|---|
#foo .bar |
.bar inside the element with id foo |
#foo > div:last-of-type |
Last direct child div under the element with id foo |
.modal-backdrop |
First element with class modal-backdrop |
[data-testid="newsletter-popup"] |
Element with a specific data-testid value |
body > div[role="dialog"] |
Dialog div directly under body |
Note:
div:last-childanddiv:last-of-typeare not equivalent.
Use> div:last-of-typewhen you want the last direct childdivof a container.
- Allows the content script to run on any
http/httpspage. - Hides only the first element matching the selector.
- One rule per domain (the popup overwrites the previous selector on save).
- No data leaves your browser. No external requests are made. (Clean & simple)
- As this is a developer-focused tool, I chose not to publish it to the Chrome Web Store.