How Websites Detect You Are Using an Ad Blocker

Photo: Szabó Viktor / Pexels
When a site tells you to switch off your ad blocker, it did not read your extension list. It set small traps, such as a hidden element with an ad-like name or a request to a URL that blockers love to cancel, and then checked whether the traps survived. Most traps need JavaScript. A few do not, and work through CSS or an HTTP status code instead. Here is how each method works, where it breaks, and why the arms race never settles.
What ad blockers actually do
To understand detection, start with what a blocker touches. Popular blockers such as uBlock Origin, Adblock Plus, and the blocker built into Brave work mostly on two layers.
Network filters decide whether a request is allowed to leave the browser at all. If a script is requested from a URL that matches a rule, the request is cancelled and the page never receives the file. The uBlock Origin wiki describes network filters as the rules that decide whether a request is loaded (uBlock Origin wiki, static filter syntax).
Cosmetic filters hide things after the page has loaded. They use CSS-style selectors, written with a ## syntax, to hide page elements. By default, in the wiki's words, their implicit purpose is to hide unwanted DOM elements. The DOM (document object model) is the browser's live tree of every element on the page.
A third layer matters for the arms race. uBlock Origin can inject small JavaScript snippets called scriptlets into specific sites. Those snippets are drawn only from code the project itself vouches for, and generic scriptlet rules that apply to every site are ignored.
Rules come from filter lists. The best known is EasyList, a community-maintained list that blockers subscribe to. The rules are written by volunteers who spot ad patterns, so a name like ad-banner or a path like /ads/ is exactly what the list tends to catch.
The two-layer design is why detection comes in two flavors. If a network rule fires, a file never arrives. If a cosmetic rule fires, the file arrives but an element is hidden. A detector has to test for the right one.
A quick note on browser rules
Not every blocker works the same way. In 2019, according to the Wikipedia article on ad blocking, Apple and Google changed their extension systems to favor declarative content blocking, in which the browser itself applies predefined filters rather than extension code deciding on each request. Both vendors limited the number of entries those lists can hold. Some critics allege, particularly of Chrome's changes, that the move reduces ad blocker effectiveness (Wikipedia, Ad blocking). Google's own Manifest V3 announcement in October 2018 framed the change as modernizing extension architecture to improve security and performance. The effect on detection is indirect: blockers that run less code on each page also leave fewer fingerprints for a detector to find.
The core idea: a tripwire that only blockers trip
Every detection method follows the same logic, and it helps to see it first. Think of a mine canary. The canary does nothing useful by itself. It exists so that something invisible, here a gas, shows up as something visible, a bird in trouble. A detection script plants a decoy that should behave one way on a clean browser and another way on a browser with a blocker, and then reads the difference.
A second analogy is a mystery shopper. A store cannot read an employee's mind, but it can send in someone who asks for a specific item and watch what happens. The publisher cannot read your extensions. It can only ask the browser to do something a blocker would interfere with, and see whether it happens.
This also explains the key limit. A detector sees only effects inside its own page. It cannot list your extensions, read your settings, or see what you do on other sites. It infers a blocker from a missing file or a hidden box, and inferences can be wrong.
Method 1: bait elements
The oldest and most common test plants an element that a cosmetic filter should hide. The publisher adds a small invisible block to the page with class names and IDs that appear in filter lists, such as ad-slot, adBanner, or ad-leaderboard. A person never sees it, because it is a pixel or two with no content. A cosmetic filter, though, sees an advertisement container.
Then a script measures the element:
const bait = document.createElement('div');
bait.className = 'ad-slot adBanner ad-leaderboard';
bait.style.cssText = 'position:absolute;left:-9999px;height:1px;width:1px;';
document.body.appendChild(bait);
window.setTimeout(() => {
const style = window.getComputedStyle(bait);
const hidden =
bait.offsetHeight === 0 ||
style.display === 'none' ||
style.visibility === 'hidden';
if (hidden) {
// a cosmetic filter probably hid the bait
}
bait.remove();
}, 100);
If a blocker hides the element, its height collapses to zero or its display value flips to none. The script has to wait a moment, because cosmetic filters are applied after the page structure exists, not at the instant the element is created.
Why the bait needs to keep changing
Filter list maintainers read the same detection scripts publishers write. Once a bait name is in the open, a volunteer can add a rule that either blocks the detection script or tells the cosmetic filter to leave that name alone. Publishers respond by generating class names at random on each page load, so no fixed rule can match them.
That moves the fight to a harder question. If the bait is random, how does a cosmetic filter know it is an ad? It cannot. A blocker that hides only elements matching known ad patterns will leave a random bait alone, and the detector will conclude there is no blocker, even when network blocking is active. For this reason, bait elements detect cosmetic filtering specifically, not blocking in general.
What bait elements cannot do
Bait elements need JavaScript to measure the result, so they do nothing for a visitor whose scripts are off. They also fire on false positives: some privacy tools and reader modes hide elements by pattern, and a detector cannot tell those from an ad blocker.
Method 2: probing a request that a blocker would cancel
The second approach tests the network layer. The page asks for a file from a URL path that blockers dislike, and checks whether the request succeeds. The file can be tiny, even empty. The detector cares about whether the request was allowed, not what came back.
async function requestWasBlocked(url) {
try {
const response = await fetch(url, { method: 'HEAD', cache: 'no-store' });
return !response.ok;
} catch (error) {
return true; // network-level failure
}
}
requestWasBlocked('/ads/prebid.js').then((blocked) => {
// blocked === true suggests a network filter cancelled the request
});
The subtlety is in how fetch() reports problems. MDN states that a fetch promise rejects only when the request itself fails, such as a badly formed URL or a network error, and that it does not reject when the server answers with an error status such as 404 or 504 (MDN, fetch()). A request cancelled by an extension is treated as a failure, so the promise rejects. That is why a good probe checks both cases: a rejection, and a response whose ok flag is false.
Why this beats bait elements, and where it still fails
A network probe sees network blocking directly, so a publisher using it does not depend on class names. To defeat it, a blocker must let the request through, which gives up the very blocking it exists to do, or must catch the probe script itself, which means the script's URL has to reach a filter list. The publisher can then move the script.
False positives are the main weakness. A request can fail because the network dropped, a corporate proxy filtered the URL, or a privacy-focused browser blocked a known tracker path. A detector that treats every failure as an ad blocker will accuse some innocent users.
Method 3: the Resource Timing API
Browsers keep a log of every file a page loaded, and scripts can read it. The Resource Timing API exposes a PerformanceResourceTiming entry for each resource, with high-resolution timestamps for events such as DNS lookup, request start, and response end, plus size fields such as transferSize and decodedBodySize (MDN, Resource Timing).
A detector can request a set of files, some on ad-like URLs and some neutral, then compare the log. In principle, a file that never appears in the log, or one that appears with sizes and times that look wrong, is a candidate for blocking. In practice the result varies by browser and by blocker, and MDN notes a real constraint: many of the properties are restricted to return zero or an empty string for cross-origin requests unless the server sends a Timing-Allow-Origin header. A publisher can set that header for its own files, but not for third-party ad scripts it does not control.
This method is a refinement of the network probe, not a different principle. It adds more evidence, such as timing, but it shares the same weakness: a missing log entry has more than one possible cause.
Method 4: CSS alone, with no script
Now to the part that needs no JavaScript at all. The trick relies on how CSS handles a missing variable.
A publisher serves a small stylesheet from an ad-like URL, such as /ads/layout.css. The file sets a CSS custom property, a variable whose name starts with two dashes, on the document root:
/* /ads/layout.css — the URL is chosen to match a filter rule */
:root {
--notice-display: none;
}
A second stylesheet, from a neutral URL, uses the variable with a fallback:
/* main.css */
#adblock-notice {
display: var(--notice-display, block);
}
If the first stylesheet loads, the variable exists, and the notice has display: none. If a network filter blocks the first stylesheet, the variable is never defined. MDN explains that the fallback value in var() is used when the custom property has not been declared on a rule that applies to the element (MDN, var()). The notice then takes the fallback, block, and appears.
A trap in the obvious version
A tempting version of this trick stores a number in the variable, such as --adblock-detected: 0, and writes display: var(--adblock-detected, block). It does not work. MDN says that when a var() resolves to a value that is invalid for the property, the property is treated as if it had been set to unset. Zero is not a valid display value, so the notice would fall back to the default display behavior and show up for everyone. The variable has to hold a real, valid value of the property it feeds, such as none.
What CSS can and cannot do
This approach never touches JavaScript, so it works for a visitor with scripts disabled. It also has hard limits:
- It shows or hides elements. It cannot build a modal, set a cookie, or lock content on its own.
- It cannot distinguish a blocked stylesheet from a failed one. A flaky network will show the notice to a person with no blocker.
- A filter list maintainer can add the stylesheet URL to an allow rule, or simply not block it.
A related no-script idea uses CSS to request an image, for example as a background on a hidden element, with a unique token in the URL. The server then checks whether it saw the image request for that token. The page itself never knows the answer, but the server does, and it can serve a different version of the page on the next load.
Method 5: HTTP 103 Early Hints
The most unusual technique uses a feature built to speed up page loads. HTTP 103 Early Hints is an informational response a server can send while it is still preparing the real answer. MDN describes it as a way to tell the browser which sites and resources the final response will probably need, so the browser can preconnect or preload them before the 200 OK arrives. Hints travel in the Link header, and MDN recommends sending 103 only over HTTP/2 or later (MDN, 103 Early Hints).
The idea for using it against blockers appeared as a Show HN post by the user mechazawa on March 25, 2024, linking to a project called 103-early-anti-adblock. The post collected 108 points and 199 comments (Hacker News).
How the Early Hints trick works
The server sends a 103 response asking the browser to preload a dummy file, such as an adv.css with a unique token in its name. A browser with no blocker fetches the file, and the request reaches the server. If a blocker stops the fetch, the request never arrives. The server, which was waiting, concludes that a blocker is present and can serve a different page when it sends the real response. No JavaScript runs in the browser at any point, because the detection is entirely on the server side.
Why it is more fragile than it sounds
The project's own README is candid about limits (103-early-anti-adblock on GitHub):
- The technique works only in Firefox. Chrome prevents blockers from interacting with early-hinted resources and hides them from the developer console, so the test sees nothing useful there. Safari does not support preload early hints.
- It needs HTTP/2, which means a valid TLS certificate even for a local test.
- Browsers without full support can be identified by preloading a harmless dummy resource that blockers do not block.
- The author states that earlier techniques working during the server response are more effective and less prone to false positives, though more involved to implement.
Commenters on the Hacker News thread raised practical costs. The server has to hold the response in memory while it waits for the browser to react, which adds latency and is hard to run across several servers. Suggested countermeasures included having blockers fetch early-hint resources anyway, or ignoring Early Hints altogether. MDN adds another limit: browsers process only the first early hints response.
The technique is sometimes described as page-side code that checks the browser cache for the preloaded file. That is not how the project describes it. The check happens on the server, which is the reason it needs no script.
Comparing the methods
| Method | Needs JavaScript | What it detects | Main weakness |
|---|---|---|---|
| Bait element | Yes | Cosmetic filtering | Randomized names are not matched by filters, so the test may see no blocker |
Network probe with fetch() |
Yes | Network filters | A failed request has many other causes |
| Resource Timing comparison | Yes | Network filters, with extra evidence | Cross-origin timing is restricted, and results vary by browser |
| CSS variable fallback | No | Network filters on a stylesheet | Cannot separate blocking from a failed load, and can only change what CSS renders |
| HTTP 103 Early Hints | No | Network filters on a preloaded file | Reported to work only in Firefox, needs HTTP/2, and costs server memory |
The table shows a pattern. The stronger a method is at proving a blocker exists, the more it depends on JavaScript. The methods that avoid JavaScript are narrower, and each is easier to break.
How blockers fight back
A detection script is just code and URLs, and blockers can act on both.
Filter rules against the detector. A volunteer who finds a detection script can add its URL to a filter list, so the script never loads. Publishers answer by renaming the file or serving it from their own domain, which blockers do not want to block wholesale.
Allowing the bait. A rule can tell the cosmetic filter to ignore a bait name. That defeats the check without touching the script.
Scriptlets. The uBlock Origin wiki says a scriptlet filter allows the injection of specific JavaScript code into pages, and that the code must be vouched for by the project. A scriptlet can alter what a detection script sees, for instance by changing what the bait element reports. The restriction to site-specific rules keeps the approach narrow.
Anti-adblock vendors push back. Wikipedia records an incident in August 2017 in which an anti-adblock vendor, Admiral, sent a DMCA section 1201 demand to have a domain removed from a filter list, a sign that the dispute has also been fought through legal channels.
An arms race with limits
A 2017 paper by Grant Storey, Dillon Reisman, Jonathan Mayer, and Arvind Narayanan modeled the contest as a security arms race with four states and six transitions. The authors argued against the assumption that it will escalate indefinitely, saying the outcome depends on a mix of technical and legal factors. One idea in the paper rests on a simple fact: ads must be recognizable by humans to comply with laws and industry self-regulation, so a blocker that spots ads the way a person does is hard for a publisher to hide from (Storey et al., arXiv:1705.08568).
The asymmetry is real. A publisher must catch blockers without annoying visitors who have none, so every extra bit of sensitivity risks more false positives. A blocker only has to beat the detector for its own users, and has no false-positive problem to manage.
Server-side ad insertion: when there is nothing to block
The strongest answer to blockers does not detect them at all. If the ad is stitched into the same stream as the content, there is no separate request to cancel.
According to the Wikipedia article on ad blocking, YouTube began warning viewers who use ad blockers in September 2023, saying they could be blocked from content after three videos unless they allowed the site or bought YouTube Premium. In June 2024 the company began experimenting with server-side ad insertion, which the article says makes automatic blocking significantly more difficult. In this model, the server merges the ad into the video stream before it reaches the browser, so the browser sees one stream and a filter has no obvious URL to match.
That is a different kind of countermeasure from the five methods above. Detection tries to find out whether you blocked something. Server-side insertion makes sure there is nothing separate to block. Blockers can still respond with other approaches, such as skipping or muting ad segments, but those need different tools than a URL filter.
Why people block ads in the first place
Detection looks different once you see what drove adoption. The Wikipedia ad-blocking article cites a figure of 27 percent of US internet users using ad-blocking software as of 2021 (cited there to Statista), and 58 percent of technical audiences blocking ads (cited to Plausible Analytics, August 2021). Survey numbers differ by source and method, so treat these as one snapshot, not a settled rate.
The privacy case is easiest to see in measurement research. In a study of the top one million websites, crawled in January 2016, Steven Englehardt and Arvind Narayanan found more than 81,000 third parties on at least two first-party sites, though only 123 appeared on more than one percent of sites. Google, Facebook, and Twitter were the only third-party entities on more than 10 percent of sites. Canvas fingerprinting, a technique for recognizing a browser by how it draws hidden images, appeared on 14,371 sites. Ghostery, a blocker, cut the average number of third-party includes per site from 17.7 to 3.3 (Princeton Web Census).
Those numbers are a decade old, and the specifics have moved. They still show why many people see a blocker as a privacy tool first and an ad tool second. For readers who want the practical side of that choice, the article on how to protect your online privacy covers the wider toolbox, and cybersecurity threats in 2026 covers the risks that ad networks can carry.
The publisher's side
Publishers see the same web differently. Ad revenue pays for much of the content that people read for free, and blocking at scale reduces that revenue. Detection lets a publisher ask visitors to disable a blocker, subscribe, or accept a lighter experience. Many publishers choose to ask gently, because an aggressive wall can drive a reader away from the page for good.
Both views contain real claims. The technology does not settle them. Whether detection is acceptable, and whether reading a visitor's browser behavior needs consent, has been argued since at least 2016. The Wikipedia article's reference list includes a 2016 report that a privacy consultant claimed detection could break EU law, and a 2016 IAB Europe guidance document on ad blocking detection. Those sources show that the legal question is contested, not that it has been resolved.
What detection can and cannot see
Misunderstandings about detection are common, so a few clarifications help.
It cannot read your extension list. A page can see only what happens inside the page. It infers a blocker from effects such as a hidden bait element or a failed request.
It cannot see other tabs or sites. Detection works per page. A site learns nothing about your browsing elsewhere from a bait element.
It is often a guess. Failed requests, corporate proxies, DNS filters, and some privacy browsers can produce the same signals as an ad blocker.
Turning off JavaScript does not make you invisible. CSS and Early Hints methods can still run, although what a page can do with the result is limited without scripts.
A detection script can be blocked too. The same filter lists that hide ads can hide the script that looks for them.
How these tricks work depends on core web mechanics. The article on how browsers render web pages explains the order in which stylesheets, scripts, and elements are processed, and how HTTP status codes guide browsers covers why a 103 response differs from a 200. For the delivery side, how CDN caching speeds up websites shows why a file might be present in one place and missing in another, and what server-side rendering solves explains why a server can decide what to show before any script runs.
Frequently Asked Questions
Q: Can websites detect ad blockers if JavaScript is completely disabled? A: In some cases. A stylesheet served from an ad-like URL can set a CSS variable, and a notice that depends on that variable with a fallback will appear if the stylesheet is blocked. HTTP 103 Early Hints can also work without scripts, because the server watches whether the browser fetches a preloaded file. These methods are narrow. The README of the Early Hints proof of concept reports it works only in Firefox, and CSS can only change what CSS renders.
Q: Why do some sites ask me to disable my ad blocker even when I am not running one? A: Detection infers a blocker from side effects, and other things cause the same effects. A privacy-focused browser, a DNS-level filter, a corporate proxy, or a flaky network can make a probe request fail or hide an element. A detector tuned for high sensitivity will accuse some people who run no blocker, which is the main reason aggressive walls annoy ordinary visitors.
Q: What is the difference between a network filter and a cosmetic filter? A: A network filter decides whether a request is allowed at all, so a file never arrives. A cosmetic filter lets the page load and then hides elements that match a selector. Detection tests differ for each: a missing or failed request points to a network filter, while a hidden bait element points to a cosmetic one.
Q: Why does the HTTP 103 method work only in some browsers? A: The proof-of-concept project reports that it works only in Firefox. Chrome prevents blockers from interacting with early-hinted resources and hides them from developer tools, and Safari does not support preload early hints. MDN also notes that browsers process only the first early hints response, and recommends sending 103 only over HTTP/2 or later.
Q: Can ad blockers hide from detection scripts? A: Often, for a while. Blockers can add rules that stop a detection script from loading, tell cosmetic filters to ignore bait elements, or inject vetted scriptlets that change what a detector sees. Each fix invites a new detection tweak. A 2017 paper by Storey and colleagues argues that the contest will not escalate forever, because outcomes also depend on legal factors.
Q: Does server-side ad insertion mean ad blockers will stop working? A: Not entirely, but it makes URL-based blocking harder. When the server merges an ad into the same stream as the content, the browser has no separate ad request to cancel. YouTube began experimenting with this approach in June 2024, according to Wikipedia. Blockers can respond with other techniques, such as skipping segments, but those are less simple than a filter rule.
Q: Is ad blocker detection legal? A: It depends on the place and on how detection is done, and the question is contested. Observing what loads on your own page is a different act from storing information on a visitor's device. In the EU, some privacy advocates argued as early as 2016 that detection scripts may need consent, while industry bodies published guidance on the practice. This article is general information, not legal advice.
The takeaway
Every ad blocker detection method is a question of the same shape: did something that a blocker would stop actually happen? A hidden bait element, a failed request, a stylesheet that never defined a variable, a preload that never reached the server. The answer is only ever an inference, and an inference can be wrong in both directions.
That fragility is why the contest keeps changing form. As filter lists and scriptlets improve, publishers either move detection to places blockers cannot reach, such as the server, or sidestep it with ads that arrive inside the content stream. Neither side wins permanently, and the users caught in between are the ones who get the false alarms.
Sources
- uBlock Origin wiki, Static filter syntax (network filters, cosmetic filters, scriptlets)
- MDN Web Docs: fetch(), Resource Timing, var(), 103 Early Hints
- mechazawa, 103-early-anti-adblock and the Show HN thread, March 25, 2024
- Storey, G., Reisman, D., Mayer, J., and Narayanan, A. (2017), The Future of Ad Blocking: An Analytical Framework and New Techniques
- Englehardt, S. and Narayanan, A. (2016), Princeton Web Census: Online Tracking, a 1-million-site Measurement
- Wikipedia, Ad blocking (adoption figures, YouTube timeline, Manifest changes, EasyList)
Read next:
Follow new articles
Add SciHub101 to your feed reader to see new science and technology stories.
About the Author
SciHub101 is an independent science and technology publication founded and edited by Buğra Sözeri, a software engineer and app developer based in Türkiye. AI tools assist with drafting and research. Source documentation in the existing archive is uneven, and articles are being reviewed and corrected. The Editorial Team byline identifies editorial responsibility; it does not certify specialist or independent human review. Where we compare products, anything built by our own team is labelled as such — see the editorial guidelines and About page for how corrections and disclosures work.
Related Articles

Next.js 15: The Developer's Guide to App Router, Server Components, and Turbopack
Next.js 15 shipped in October 2024 and made the App Router the official default for new projects, stabilized Turbopack for development builds, and introduced async request APIs that changed how developers access cookies, headers, and search parameters. Next.js 16 (October 2025) extended Turbopack to production. This guide covers the concepts, architecture decisions, and practical trade-offs of the Next.js 15 era, which remains the most widely deployed major version.

How to Use Figma for Beginners: UI Design Crash Course 2026
Figma is a browser-based design tool used by 99% of product teams and freelance designers. Unlike Photoshop or Sketch, Figma runs entirely in the browser, eliminates version control chaos, and enables real-time collaboration. Core concepts: Frames (artboards), Components (reusable design elements), Auto Layout (responsive design without code), and Prototyping (clickable mockups). A beginner workflow involves creating a Frame, adding shapes/text, converting frequently-used elements to Components, applying Auto Layout for scaling, and prototyping interactions. Most beginners spend 60% of time fighting tools instead of designing. This article covers what Figma actually is, the five foundational concepts, a beginner's first-hour workflow, and practical keyboard shortcuts that save hours of clicking.

How Facial Recognition Works: From Pixels to Face Embeddings
Facial recognition turns a face into a short list of numbers and compares it with stored lists. Here is how detection, embeddings, and thresholds work, and why error rates differ across groups and settings.

How Social Engineering Hacking Works — Why Humans Are the Weakest Link
The most sophisticated cyberattacks don't exploit code — they exploit people. Here's how phishing, pretexting, spear phishing, and vishing manipulate human psychology to bypass any technical defense.

How Ransomware Works — The Cybercrime That Shuts Down Hospitals
Ransomware has crippled hospitals, pipelines, and governments. Here is the technical reality of how attackers get in, encrypt files, steal data, and get paid, and which defenses hold up.

How Passwords Are Hacked — And How to Stop It
Your password might already be sitting in a leaked list. Here's how hackers crack, steal, and reuse credentials, and the science behind stopping them.