Quick answer: A page loaded over HTTPS tried to reach an http:// or ws:// address, and the browser refused before sending anything. For a web game this is nearly always a game hosted on an HTTPS portal that calls its own server, leaderboard or asset host without TLS. The fix is on the server: give it a certificate (a reverse proxy does this in a few lines), then use https:// and wss:// URLs. Nothing in the page can make an insecure server acceptable.
The game worked on your machine, where the page was http://localhost. Uploaded to itch.io, GitHub Pages or any other HTTPS host, the leaderboard stays empty, the multiplayer lobby never connects, or the engine file does not load, and the console has a line that starts with Mixed Content. This guide lists the message for each kind of request in Chrome, Firefox and Safari, which requests are blocked and which are quietly upgraded, how to put TLS in front of a game server, and what the localhost exception and the upgrade-insecure-requests directive can and cannot do.
- The exact error
- What is blocked and what is upgraded
- How web games run into it
- Find every insecure request
- Fix: put TLS in front of the server
- Fix: build the URLs for the secure server
- The localhost exception
- The upgrade-insecure-requests directive and its limits
- Confirm the fix
- What Bugnet sees when a request is blocked
- Related guides
- Frequently asked questions
The exact error
Chrome names the kind of request in the message. These four are the ones games run into: fetch, XMLHttpRequest, a WebSocket and a script tag.
Mixed Content: The page at 'https://play.mygame.example/game/index.html' was loaded over HTTPS, but requested an insecure resource 'http://api.mygame.example/scores'. This request has been blocked; the content must be served over HTTPS.
Mixed Content: The page at 'https://play.mygame.example/game/index.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.mygame.example/scores'. This request has been blocked; the content must be served over HTTPS.
Mixed Content: The page at 'https://play.mygame.example/game/index.html' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://api.mygame.example:8080/ws'. This request has been blocked; this endpoint must be available over WSS.
Mixed Content: The page at 'https://play.mygame.example/game/index.html' was loaded over HTTPS, but requested an insecure script 'http://cdn.mygame.example/phaser.min.js'. This request has been blocked; the content must be served over HTTPS.
Firefox and Safari use one sentence for every blocked request:
| Browser | Blocked request | Upgraded request (images, audio, video) |
|---|---|---|
| Chrome, Edge | Mixed Content: The page at '...' was loaded over HTTPS, but requested an insecure resource '...'. This request has been blocked; the content must be served over HTTPS. | Mixed Content: The page at '...' was loaded over HTTPS, but requested an insecure element '...'. This request was automatically upgraded to HTTPS (a warning, followed by a link) |
| Firefox | Blocked loading mixed active content “http://...” | Mixed Content: Upgrading insecure display request ‘http://...’ to use ‘https’ |
| Safari | [blocked] The page at https://... requested insecure content from http://.... This content was blocked and must be served over HTTPS. | The page at https://... requested insecure content from http://.... This content was automatically upgraded and should be served over HTTPS. |
What your code receives
The console message is for you. Your JavaScript gets a generic failure with no mention of mixed content, which is why the game’s own error text is usually no help:
| API | Chrome | Firefox | Safari |
|---|---|---|---|
fetch() | Rejects with TypeError: Failed to fetch | Rejects with TypeError: NetworkError when attempting to fetch resource. | Rejects with TypeError: Load failed |
XMLHttpRequest | onerror fires, status is 0 | onerror fires, status is 0 | onerror fires, status is 0 |
new WebSocket("ws://...") | The constructor throws SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS. | No exception. The socket fires error, then close with code 1006 | No exception. The socket fires error and never opens |
<script src>, stylesheet | The element’s error event fires | The element’s error event fires | The element’s error event fires |
The WebSocket row is a portability trap: code that wraps the constructor in try/catch handles Chrome and misses the other two, and code that only listens for error crashes in Chrome. Handle both. A blocked engine script usually surfaces as a second error, covered in the guide to “is not defined”.
What is blocked and what is upgraded
Browsers sort insecure requests from a secure page into two groups. Requests that can read data or run code are blocked outright. Requests that only display or play something are rewritten to https:// and sent, with no fallback to http:// if that fails. Current Chrome, Firefox and Safari all behave this way:
| Request | Result |
|---|---|
fetch, XMLHttpRequest, EventSource, navigator.sendBeacon | Blocked |
ws:// WebSocket | Blocked |
| Scripts, stylesheets, web fonts, iframes, workers | Blocked |
<img src>, <audio src>, <video src>, new Image(), new Audio() | Upgraded to https://. Loads only if the host answers there |
| The same elements when the host is an IP address | Not upgraded. Chrome and Safari block the request |
http://localhost and http://127.0.0.1 | Treated as secure by Chrome and Firefox. See the localhost section |
The upgrade row helps games less than it seems. Most engines load images and sounds through fetch or XMLHttpRequest so they can decode them into textures and audio buffers, and that puts those assets in the blocked group even though they are pictures and sounds.
The check runs before the request leaves the browser, so the server never sees it and has nothing in its logs. The reason for the rule is simple: anyone on the network path can read and rewrite an unencrypted response, and a rewritten script or score payload would run with the full trust of the secure page.
How web games run into it
- The game moved to an HTTPS host and the backend did not. itch.io, GitHub Pages and the other portals serve everything over HTTPS, and itch.io’s documentation says external resources must be requested over HTTPS with no exceptions. A leaderboard at
http://203.0.113.10:3000worked fromhttp://localhostbecause that page was not secure, so there was nothing to mix. - A multiplayer server reached with
ws://, often by raw IP address and port. - Assets on a host without TLS. A storage bucket’s plain-HTTP website endpoint, an old CDN URL, a file server on a VPS.
- A hardcoded
http://you forgot about: in a config file, in level data that lists asset URLs, in a stylesheet, or inside a third-party snippet. - A redirect. An
https://URL that redirects tohttp://is blocked at the redirect.
Find every insecure request
- Open the deployed game (not the local one) with DevTools open and type
Mixed Contentinto the console filter. Each line names the exact URL. - In the Network tab, blocked requests appear in red with a blocked status and no response. Add the Scheme column (right-click the table header) to see
httpandwsentries at a glance. - Search the project for the schemes themselves, including data and config files, with the command below.
- Check URLs that are built at runtime: a server list fetched from your API, or a matchmaking response that returns
ws://addresses. Those do not show up in a search of the client code.
grep -rnE "(http|ws)://" src/ public/ --include="*.js" --include="*.ts" --include="*.json" --include="*.html" --include="*.css"
Fix: put TLS in front of the server
The server has to answer on https:// and wss:// with a certificate browsers trust. You do not need to change the game server’s code. Run a reverse proxy on the same machine: it holds the certificate, accepts the encrypted connection and passes plain traffic to your server on a local port.
Certificates are normally issued for domain names, so first point a domain or subdomain at the server, for example api.mygame.example. With Caddy, which obtains and renews the certificate by itself, the whole configuration is:
api.mygame.example {
reverse_proxy localhost:3000
}
With nginx and a Let’s Encrypt certificate from certbot, the server block needs the upgrade headers so WebSockets pass through:
server {
listen 443 ssl;
server_name api.mygame.example;
ssl_certificate /etc/letsencrypt/live/api.mygame.example/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.mygame.example/privkey.pem;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
The same proxy serves both the HTTP API and the socket: wss://api.mygame.example/ws arrives on port 443 and is forwarded to your server as an ordinary WebSocket. If the secure socket then fails to connect, the cause is in the proxy or the handshake, which is the subject of the WebSocket handshake guide.
Two shortcuts do not work. A self-signed certificate is rejected by players’ browsers with a certificate error, so the request still fails. And once the API is on a different origin from the game with working TLS, it needs CORS headers like any other cross-origin API, or the mixed content message is replaced by a CORS one.
For assets, move them to a host that serves HTTPS, or put them in the same upload as the game so they are same-origin and need no absolute URL at all.
Fix: build the URLs for the secure server
Once the server answers on TLS, use the secure scheme everywhere. An insecure page is allowed to call a secure server, so there is no need to keep an http:// variant for production:
const isLocal = ["localhost", "127.0.0.1"].includes(location.hostname);
const API_URL = isLocal ? "http://localhost:3000" : "https://api.mygame.example";
const WS_URL = isLocal ? "ws://localhost:3000/ws" : "wss://api.mygame.example/ws";
When the game and its server share a host, derive the socket scheme from the page so one build works in both places:
const wsScheme = location.protocol === "https:" ? "wss://" : "ws://";
const socket = new WebSocket(wsScheme + location.host + "/ws");
const scores = await fetch("/api/scores").then((r) => r.json());
Handle the connection failure in a way that covers all three browsers:
function connect(url, onFail) {
let socket;
try {
socket = new WebSocket(url); // Chrome throws here for ws:// on an HTTPS page
} catch (err) {
onFail(err);
return null;
}
socket.addEventListener("error", () => onFail(new Error("WebSocket failed: " + url)));
return socket;
}
The localhost exception
Browsers treat the loopback addresses as trustworthy, because traffic to your own machine does not cross a network. In Chrome and Firefox, an HTTPS page may call http://localhost:3000 or ws://127.0.0.1:3000 without a mixed content error. That is why a development setup with an HTTPS dev server and a plain local backend works.
Do not build on it beyond that:
- Safari does not apply the exception. In a test with a current WebKit build, the same requests were blocked as mixed content.
- Chrome puts requests from a public website to loopback or local network addresses behind its Local Network Access permission, introduced with a prompt in Chrome 142. A deployed build calling your local server therefore asks the user for permission first, and fails if it is denied.
- A LAN address such as
http://192.168.1.20:3000gets no exception in Firefox or Safari, and in Chrome it depends on that same permission.
To test a deployed build against a server on your machine, give the local server a real HTTPS address with a tunneling tool, or run the whole game locally over http://localhost, where nothing is mixed.
The upgrade-insecure-requests directive and its limits
This Content Security Policy directive tells the browser to rewrite insecure URLs before requesting them. It can go in the game’s index.html:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
With it, a fetch("http://api.mygame.example:3000/scores") is sent to https://api.mygame.example:3000/scores, and no mixed content message appears. In Chrome and Safari a ws:// URL becomes wss:// in the same way. In a test with a current Firefox build, the WebSocket URL was not rewritten and the connection failed.
What it does not do is add TLS. The host and port stay the same, so the server must already answer HTTPS at that exact address. If it does not, the upgraded request fails with a connection or certificate error, and there is no fallback. The directive is useful when a host supports HTTPS and old content is full of hardcoded http:// asset links you cannot edit one by one. For your own server and your own code, write the secure URL.
Chrome also has a per-site Insecure content setting that allows blocked requests. It is a debugging aid for your own browser. Asking players to change it is not a fix.
Confirm the fix
- Load the deployed game and filter the console for
Mixed Content. There should be no lines, including no upgrade warnings. - In the Network tab, check the Scheme column: only
httpsandwss. - Submit a score and join a match from the portal page, not from a direct link to your own domain. The page origin is different there, which also tests your CORS setup.
- Repeat in Firefox and Safari, paying attention to the WebSocket path.
What Bugnet sees when a request is blocked
The browser’s Mixed Content line is written to the console by the browser, not by your code, so no script on the page can read it, the Bugnet Web SDK included. What the SDK sees is what your code sees. A blocked fetch that nobody catches arrives at its unhandledrejection listener as TypeError: Failed to fetch and is filed once per session with the last 50 console lines, the user agent and the game version. That report cannot distinguish mixed content from CORS or a dead connection. Chrome’s WebSocket case is the exception: the constructor throws a SecurityError whose message states the cause, and an uncaught one is filed with that text. A blocked script or stylesheet produces no report by itself.
You can close the gap with one check, since mixed content is detectable before the request: if location.protocol is "https:" and the URL you are about to use starts with http: or ws:, call Bugnet.reportBug("Insecure server URL on HTTPS page", url, { category: "network" }). Reports with the same title stack into one entry with an occurrence count, so a bad URL in a server list shows up as one entry. The SDK’s own requests go to an HTTPS endpoint and are not affected. Setup is in the SDK docs.
Related guides
- How to Fix “WebSocket connection failed: Error during WebSocket handshake” in Multiplayer Web Games
- How to Fix “TypeError: Failed to fetch” in a Web Game
- How to Fix Game Assets Blocked by CORS When Served From a CDN
- How to Fix a Web Game Blocked by Content Security Policy
- How to Fix a Web Game That Works Locally but Returns 404s on GitHub Pages or itch.io
Frequently asked questions
What does a Mixed Content error mean?
The page was loaded over HTTPS and tried to load or call something over plain http:// or ws://. Browsers block such requests before they are sent when they could read data or run code, which covers fetch, XMLHttpRequest, WebSockets, scripts and stylesheets.
Why does my game work locally but show Mixed Content on itch.io or GitHub Pages?
Locally the page is served from http://localhost, which is not a secure page, so a call to an http:// server mixes nothing. Portals serve your game over HTTPS, and from there every request to an http:// API or ws:// game server is blocked.
How do I fix an insecure WebSocket endpoint error?
Make the server reachable over wss:// by putting a reverse proxy with a TLS certificate in front of it, then connect with a wss:// URL. In Chrome the WebSocket constructor throws a SecurityError for ws:// on an HTTPS page, while Firefox and Safari fire an error event, so handle both.
Does upgrade-insecure-requests fix mixed content?
Only when the server already answers HTTPS at the same host and port. The directive rewrites http:// URLs to https:// before the request is sent and has no fallback, so against a server without TLS the request still fails with a connection error.
Can an HTTPS page call http://localhost?
Chrome and Firefox treat localhost and 127.0.0.1 as trustworthy and do not block the request as mixed content, while Safari does block it. Chrome also asks the user for a Local Network Access permission when a public site calls a loopback address, so it is a development convenience and not something a released game can rely on.
Mixed content is fixed on the server, not in the page: give the API and the game server a certificate through a reverse proxy, then use https:// and wss:// everywhere. Your code only ever sees a generic network failure, so read the console on the deployed build.