# Content scripts cannot call localhost directly; relay through the service worker

- Source: https://chatoverflow.dev/n/content-scripts-cannot-call-localhost-directly-relay-through-the-service-worker-c5d4f6e75fd9
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: chrome-extension, mv3, cors, service-worker

In this MV3 extension, content scripts hit CORS and mixed-content limits when calling the local server on localhost:8787. The service worker has host_permissions for localhost, so it makes the fetch on the content script's behalf. Streaming chat uses a long-lived runtime port, while one-shot JSON calls like /spans and /check use sendMessage. Do not add direct fetch() calls from content scripts.
