How to Prevent Bots from Scraping Your Content

September 8, 2023
September 8, 2023

Learn more about Fingerprint

  • Streamline user experiences for trusted traffic
  • The highest accuracy device identification for mobile and web
  • Improve visitor analytics on mobile and web
Talk to our Team

What is content scraping?

Content or web scraping extracts valuable data from websites using automated scripts or bots. If your website contains expensive data to collect or compute (e.g., flight connections, real-estate listings, product prices, or user data), a bad actor or competitor could steal and use it for nefarious purposes. Your data could also be scraped by browsing plugins for generative AI models like ChatGPT and used to answer user queries or train large language models without your knowledge.

Bots vary in their ability to scrape content and avoid detection. Simple scripts using an HTTP library like wget can retrieve pages from a web server and parse information from the HTML response. They can be effective for scraping static sites but less efficient for dynamic client-rendered content. They are also easier to detect as your website can easily test its inability to execute JavaScript.

Headless browsers and browser automation tools like Puppeteer or Selenium are much more sophisticated. They can execute JavaScript, scroll, press buttons, wait for client-rendered content to load, and scrape it. They are full-featured browsers, only automated, which makes them more robust and harder to detect. Many also have “stealth” plugins, which try to make them resemble regular browsers.

Please review our article on understanding content scraping to learn more about how it works and its impact on website owners.

Protect your content from sophisticated bots

A web application firewall (WAF) can provide an essential layer of rule-based protection, such as blocking IP ranges, countries, and data centers known to host bots. This first line of defense is helpful but sometimes insufficient, as scrapers can use proxies to cycle through different IP addresses.

You can ask your visitors to prove they’re human by completing CAPTCHA challenges, like picking all the images that contain a sombrero. This is generally effective but also disruptive to the user experience. To fight bots without bothering humans, you can use a client-side library to detect bots at runtime by analyzing the visitor’s browser.

Fingerprint Pro Bot Detection collects vast amounts of browser data that bots leak (errors, network overrides, browser attribute inconsistencies, API changes, and more) to reliably distinguish real users from headless browsers, automation tools, their derivatives, and plugins.

It is based on BotD — a free and open-source library that we created that detects simple bots running entirely in the client. Fingerprint Pro Bot Detection, however, can detect a broader range of sophisticated bots and runs the analysis on the server side, where it’s not vulnerable to tampering by bots themselves. See our documentation for a detailed comparison of BotD and Fingerprint Pro Bot Detection. The example below uses the non-open-source version.

Integrate Fingerprint Bot Detection into your website

First, sign up for a Fingerprint account. Bot detection is included in the Pro Plus plan as one of the Smart signals alongside incognito mode detection, VPN detection, browser tampering detection, and other data points useful for securing your website.

Add the JavaScript agent to your website client. Once enabled, you can use the same JavaScript agent for visitor identification and Bot Detection. We have client libraries for all significant front-end frameworks, or you can load the script from our CDN as shown below:

// Initialize the agent.
const fpPromise = import('<your-public-api-key>')
  .then(FingerprintJS => FingerprintJS.load({
    endpoint: '<>',

Note: For production deployments, we recommend routing requests to Fingerprint Pro APIs through your own domain — that’s what the endpoint parameter is for. This prevents ad blockers from disrupting identification requests and improves accuracy. We offer various proxy integration options; see Protecting your JavaScript agent from ad blockers for more details.

Let’s use an airline website as an example. The visitor picks their destination and clicks “Search flights.” Before returning the results from the server, you want to ensure they are not a bot.

Example website for searching flights

On the client, right before requesting the flight data, use the loaded fpPromise to send browser parameters to Fingerprint Pro API for analysis. You will get a requestId in the response. Include it in the search request you send to your server.

async function onClickSearchFlights(from, to) {
  // Collect browser signals for bot detection and send them
  // to the Fingerprint Pro API. The response contains a requestId.
  const { requestId } = await (await fpPromise).get();

  // Pass the requestId to your server alongside the flights query
  const response = await fetch(`/api/web-scraping/flights`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    body: JSON.stringify({ from, to, requestId }),

Note: Fingerprint Pro must collect signals from the browser to detect bots. Therefore, it is best used to protect data endpoints accessible from your website, as this article demonstrates. It is not designed to protect server-rendered or static content sent to the browser on the initial page load, as browser signals are unavailable during server-side rendering.

On the server, send the requestId to Fingerprint Pro Server API to get your bot detection result. If the requestId is malformed or not found, it will not return the flight results. You can call the Server API REST endpoint directly or use one of our Server SDKs. Here is an example using the Node.js SDK:

import {
} from "@fingerprintjs/fingerprintjs-pro-server-api";

export default async function getFlightsEndpoint(req, res) {
  const { from, to, requestId } = req.body;

  // RequestId is in the wrong format and can be rejected immediately.
  if (!/^\d{13}\.[a-zA-Z0-9]{6}$/.test(requestId)) {
      message: "Malformed requestId, potential spoofing detected.",

  let botDetection;
  try {
    // Initialize the Server API client.
    const client = new FingerprintJsServerApiClient({
      region: Region.Global,
      apiKey: "<YOUR_SERVER_API_KEY>",

    // Get the analysis event from the Server API using the requestId.
    const eventResponse = await client.getEvent(requestId);
    botDetection = eventResponse.products?.botd?.data;
  } catch (error) {
    // If getting the event fails, it's likely that the
    // requestId was spoofed, so don't return the flight results.
      message: "RequestId not found, potential spoofing detected.",

  // Continue processing the botDetection result...

The botDetection result returned from the Server API tells you if Fingerprint Pro detected a good bot (for example, a search engine crawler), a bad bot (an automated browser), or not a bot at all.

  "bot": {
    "result": "bad" // or "good" or "notDetected",
      "type": "headlessChrome"
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/110.0.5481.177 Safari/537.36",
  "url": "",
  "ip": "",
  "time": "2023-09-08T16:43:23.241Z",
  "requestId": "1234557403227.AbclEC",

If the visitor is a malicious bot, return an error. Optionally, you could update your WAF rules to block the bot’s IP address in the future.

// Determine if a bad bot was detected.
if (botDetection?.bot.result === 'bad') {
    message: "Malicious bot detected, scraping flight data is not allowed."

At this point, you will know which fingerprinting requests are real and with no malicious bots detected. But you need to verify that the result actually belongs to this search request. The bot could have replaced the real requestId with an old one obtained manually some time ago. To check against replay attacks, you need to verify the freshness of the fingerprinting request:

// Fingerprinting event must be a maximum of 3 seconds old.
if ( - Number(new Date(botDetection.time)) > 3000) {
    message: "Old visit detected, potential replay attack.",

You also want to verify that the origin of the fingerprinting request matches the origin of the search request itself. Usually, both will be coming from your website’s domain.

const fpRequestOrigin = new URL(botDetection.url).origin;
if (
  fpRequestOrigin !== req.headers["origin"] ||
  fpRequestOrigin !== "" ||
  req.headers["origin"] !== ""
) {
    message: "Origin mismatch detected, potential spoofing attack.",

Finally, verify that the fingerprinting request's IP matches the search request's IP.

if (botDetection.ip !== req.headers["x-forwarded-for"]?.split(",")[0]) {
    message: "IP mismatch detected, potential spoofing attack.",

Having verified the authenticity of the bot detection result, you can now confidently return the flights:

const flights = await getFlightResults(from, to);
res.status(200).json({ flights });

Explore our Web Scraping Prevention Demo

Visit the Web Scraping Prevention Demo we built to demonstrate the concepts above. You can explore the open-source code on Github or run it in your browser with StackBlitz. The core of the use case is implemented in this component and this endpoint.

To see Fingerprint Pro Bot Detection in action, you must visit the use case website as a bot. The easiest way is to use a Browserless debugger, which allows you to control an automated browser in the cloud from your browser.

  1. Go to the Fingerprint’s Browserless instance.

  2. Switch to the Web Scraping tab for a full bot example, or copy this snippet into the code editor:

    export default async ({ page }: { page: Page }) => {
      await page.goto('');
  3. Press the “Play” button in the top right to run the bot (and wait a few seconds).

  4. In the developer console, in the bottom right, you can see a request made to failed with a 403 Forbidden error. Clicking on this will take you to the Network tab, where you can see the full response:

    	"message": "🤖 Malicious bot detected, access denied.",
    	"severity": "error",
    	"type": "MaliciousBotDetected"

The automated browser can’t access the flight search results when Bot Detection is enabled.

A screenshot of an automated browser failing to scrape a website protected by Fingerprint Pro Bot Detection.

If you prefer to explore and test locally, the demo contains end-to-end tests. Execute them to see that you can scrape the flight results with Bot Detection disabled, but not otherwise.

git clone
cd fingerprintjs-pro-use-cases
yarn install
yarn dev

# In a second terminal window
yarn test:e2e:chrome e2e/scraping/protected.spec.js --debug
yarn test:e2e:chrome e2e/scraping/unprotected.spec.js --debug

If you have any questions, please reach out to our support team. You can view this and other live technical demos and their source code on GitHub.