# "Refused to execute inline script": why your app shows a blank page

Your app worked yesterday. Today it opens to a blank page, or the buttons do nothing. Open the browser's developer tools and the console says something like:

```
Refused to execute inline script because it violates the following
Content Security Policy directive: "script-src 'self'".
```

Nothing is broken in your code. The site has a **Content Security Policy**, and it's doing its job. Here's what that means, and how to fix it in a few minutes.

![Code written inside the page is blocked by the policy. The same code in its own file, loaded with a script tag, runs.](/blog/images/inline-script-blocked.svg)

## What a Content Security Policy is

It's a rule the site sends with every page, telling the browser what it may load and run. A common one says: only run scripts that come from this site's own files.

The point is protection. If an attacker manages to slip some text into your page, such as a comment with a `<script>` in it, the browser refuses to run it. A policy like this is one of the best defences against that kind of attack, so the fix is to change the page, not to switch the policy off.

## What counts as inline

The policy blocks code written inside the page itself:

- `<script>` tags with code between them, instead of a `src`
- `onclick="…"`, `onload="…"` and other `on…` attributes
- links like `<a href="javascript:…">`
- code built from text at run time, with `eval()` or `new Function()`

AI tools write all of these often, because they keep a small app in a single file.

## Why it started suddenly

Usually because the policy changed, not your code. Some reasons:

- You moved to a host, or a host plan, that sends a policy.
- You added a security setting or a plugin that sets one.
- On Toupas, an app made from a chat gets a strict policy once it has **actions** (code that calls other services with your keys). An app that can reach your accounts needs the stronger protection.

If the app is installed on a phone, an old copy of the page can also keep showing for a while. More on that in [installing apps on your phone](/blog/make-your-app-installable-on-phone).

## How to fix it

Move the code into a file.

**Before:**

```html
<button onclick="save()">Save</button>
<script>
  function save() { /* … */ }
</script>
```

**After:**

```html
<button id="save">Save</button>
<script src="/app.js"></script>
```

```js
// app.js
document.getElementById('save').addEventListener('click', save);
function save() { /* … */ }
```

Do the same for styles from another site, such as web fonts. A policy that allows only the site's own files blocks them too, so either put the font files in your app, or allow the font service by name.

**Tell your agent:** "The site's Content Security Policy blocks inline code. Move every inline script and `on…` attribute into .js files, and check the console is clear."

## Why not just loosen the policy?

You can add `'unsafe-inline'` to the policy and the error goes away. So does most of the protection: the browser can no longer tell your code from an attacker's. Use it only as a short-term fix while you move the code, if at all.

## How Toupas helps

On Toupas, an app made from a chat with a strict policy can't go live with inline code at all: publishing stops and says which file and line to move, so the chat fixes it before anyone sees a blank page. Apps without the strict policy get the same list as a warning.

When something is blocked anyway, the app's problem list says *what* was blocked: inline code, a file, a browser extension or another site. You can ask the chat "why is my app blank?" and it can read that list.

## Questions

### What does "refused to execute inline script" mean?

The site's Content Security Policy only allows scripts from its own files, and the browser found code written inside the page. Move that code into a .js file.

### How do I fix a Content Security Policy error?

Read which rule was broken in the console message. For script-src, move inline code and `on…` attributes into files. For style-src or font-src, host the files yourself or allow that site in the policy.

### Should I add unsafe-inline to my Content Security Policy?

Avoid it. It makes the error go away by turning off most of the protection the policy gives you.

### Why does my app work locally but show a blank page when deployed?

Often because the live site sends a Content Security Policy and your laptop doesn't. Check the browser console. [Other common causes are here](/blog/why-ai-built-app-breaks-when-you-deploy).
