JavaScript Cloaking: How It Works

JavaScript cloaking is when scripts decide what a visitor sees: crawlers that do not run JavaScript get one page, browsers that do get another.

Updated

JavaScript cloaking is when scripts decide what a visitor sees. A crawler that does not run JavaScript gets the plain HTML, a browser that does gets a different page, or is redirected.

How it works

From the Google study of ten cloaking services (Cloak of Visibility):

  • Three used JavaScript execution to block rudimentary crawlers.
  • JavaScript also serves as the delivery method for redirects.
  • One service let the operator add custom JavaScript fingerprinting code that runs on every visit.

In the paper’s measurement in the wild, “Has JavaScript support?” scored 22.4% for Google Search URLs and 49.6% for Google Ads URLs.

Study from 2016. [TODO: newer source]

Not cloaking by itself: Google tells sites that use JavaScript to make that content accessible to search engines and users without cloaking (Google spam policies).

How to spot it

Compare the page with JavaScript off and on. Free: website cloaking checker runs both. By hand: curl for the raw HTML, a headless browser for the rendered page (curl guide).

Redirect cloaking · User-agent cloaking · Website cloaking

Questions

Is using JavaScript on a page cloaking?

No. Plenty of sites render content with JavaScript. It becomes cloaking when scripts are used to show crawlers or reviewers something different from what visitors get.

How do I see a page without JavaScript?

curl fetches the raw HTML and runs no scripts. Compare it with the page a headless browser renders.