> For the complete documentation index, see [llms.txt](https://docs.bugbug.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bugbug.io/preventing-failed-tests/blocking-scripts.md). Agents can also search and read this documentation through its [MCP server](https://docs.bugbug.io/~gitbook/mcp).

# Blocking third-party scripts

Stop cookie banners, chat widgets, popups and analytics scripts from breaking or polluting your tests. Block third-party JavaScript by host or URL, no code needed.

Chat widgets, cookie banners and marketing popups can cover buttons and make tests fail at random, often with errors like "element click intercepted" or "element is covered by another element". With **Blocked scripts** you can stop the scripts that load them, so they never appear during your tests.

Only JavaScript is blocked. Styles, fonts, images and API calls still load, even from a blocked host.

Blocking works during recording and test runs, both local and in the cloud. It only affects tabs opened by BugBug, and every test and suite in the project uses the same list.

## When to block scripts

* **Cookie consent banners** (Cookiebot, OneTrust, CookieYes, Usercentrics) that cover the page or shift elements while a test clicks.
* **Live chat widgets** (Intercom, HubSpot, Zendesk, Drift, Crisp, Tawk.to, LiveChat) that open over buttons or forms.
* **Marketing popups and surveys** (OptinMonster, Hotjar) that appear at random and make tests flaky.
* **Analytics and tracking scripts** (Google Analytics, Google Tag Manager, Hotjar) so that automated test runs don't show up as real visitors in your reports.

## Add a rule

1. Open **Project settings → Browser**.
2. In **Blocked scripts**, enter a host or URL. Click **Add rule** to add more.
3. Click **Save**.
4. Start a new recording or test run. Sessions that are already open keep the old settings.

![Blocked scripts setting in Project settings → Browser](https://3168433179-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MKixgeBPbLvnD0l1eiV%2Fuploads%2FqVdGlTQS0rVbUj5cq0EA%2Fblocked-scripts-setting.png?alt=media)

To pause a rule without deleting it, turn off the switch next to it and save. To stop blocking a script for good, remove its rule and save. Remove all rules to turn blocking off.

## Rule examples

| Rule                           | What it blocks                                                                                            |
| ------------------------------ | --------------------------------------------------------------------------------------------------------- |
| `ads.example.com`              | Scripts from this host only. `cdn.ads.example.com` still loads.                                           |
| `*.example.com`                | Scripts from `example.com` and all its subdomains.                                                        |
| `https://example.com/widget/*` | Scripts whose URL starts with `https://example.com/widget/`. Other scripts from `example.com` still load. |

Start with the narrowest rule that works. Blocking a whole domain can also break login, navigation or other features your test needs.

## Common scripts to block

These are the hosts that popular tools usually load their scripts from. Providers can change them, so confirm the host in the run's [network logs](https://docs.bugbug.io/debugging-tests/network-logs.md) before you add a rule.

| Tool                           | Type               | Rule to add                                |
| ------------------------------ | ------------------ | ------------------------------------------ |
| Intercom                       | Live chat          | `widget.intercom.io`, `js.intercomcdn.com` |
| HubSpot                        | Live chat          | `js.hs-scripts.com`, `js.usemessages.com`  |
| Zendesk                        | Live chat          | `static.zdassets.com`                      |
| Drift                          | Live chat          | `js.driftt.com`                            |
| Crisp                          | Live chat          | `client.crisp.chat`                        |
| Tawk.to                        | Live chat          | `embed.tawk.to`                            |
| LiveChat                       | Live chat          | `cdn.livechatinc.com`                      |
| Cookiebot                      | Cookie banner      | `consent.cookiebot.com`                    |
| OneTrust                       | Cookie banner      | `cdn.cookielaw.org`                        |
| CookieYes                      | Cookie banner      | `cdn-cookieyes.com`                        |
| Usercentrics                   | Cookie banner      | `*.usercentrics.eu`                        |
| OptinMonster                   | Popups             | `a.omappapi.com`                           |
| Hotjar                         | Surveys, analytics | `static.hotjar.com`, `script.hotjar.com`   |
| Google Tag Manager / Analytics | Analytics          | `www.googletagmanager.com`                 |

{% hint style="info" %}
Some websites hide content or disable buttons until the visitor accepts cookies. If blocking the cookie banner breaks the page, remove the rule and accept the banner with a step in your test instead.
{% endhint %}

## Check that the rule works

1. Run the test without the rule and note the popup.
2. Add the rule and run the test again.
3. Check that the popup is gone and the page still works.

To keep it that way, add a [not-exist assertion](https://docs.bugbug.io/editing-tests/assertions.md) for the popup.

Not sure which script to block? Open the run's [network logs](https://docs.bugbug.io/debugging-tests/network-logs.md) and look for scripts from the widget's provider. Choose **Full** network logs so that scripts are included.

## Ask an AI agent to help

An agent connected through [BugBug MCP](https://docs.bugbug.io/ai-testing/mcp.md) can find the script behind a popup and add the rule for you.

{% prompt description="Block the script behind a marketing widget" icon="bug" defaultExpanded="full" %}

```markdown
In <project>, investigate the marketing widget in test run <run ID>. Find the script responsible, add a narrow blocking rule while keeping existing rules, then run the test again and check that the widget is gone and the page still works.
```

{% endprompt %}

## How this compares to Cypress, Playwright and Selenium

In code-based frameworks you block third-party requests yourself: Cypress uses the `blockHosts` setting, Playwright uses `page.route()` with `route.abort()`, and Selenium usually needs a proxy. In BugBug you add the host or URL in project settings, with no code, and the rule applies to every test and suite in the project.

## Limitations

* Blocking cannot stop scripts written directly into the page, or a popup built into the site's own code. In that case, close the popup with a step in your test.
* When the website opens a new tab itself, the first scripts in that tab may load before blocking starts.
* If BugBug cannot turn blocking on, the recorder overlay shows a warning and the test continues. Add an assertion for the popup if your test depends on the block.

## FAQ

### Does blocking scripts affect my real website visitors?

No. Rules only apply to tabs opened by BugBug during recording and test runs. Your website and its visitors are not affected.

### Do I need to add rules to every test?

No. The list is set per project, and every test and suite in the project uses it.

### Does blocking work in cloud runs?

Yes. Rules apply to local and cloud runs, and to recording.

### How do I keep test runs out of Google Analytics?

Block `www.googletagmanager.com`. If your site loads Google Analytics through that script, it won't load in BugBug tabs, so test runs aren't counted as visits. Server-side tracking is not affected.

### Can I block a script that is written directly into the page?

No. Only scripts loaded from a host or URL can be blocked. For inline scripts or popups built into your own code, close the popup with a step in your test.

### Can I turn a rule off without deleting it?

Yes. Turn off the switch next to the rule and save. The rule stays on the list, so you can turn it back on later.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.bugbug.io/preventing-failed-tests/blocking-scripts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
