在附加组件的内容脚本中向本地服务发送 POST 请求

Sending POST request to local service in the content script in an add-on

我不知道这是否可行,但我想在我的私人附加组件的内容脚本中向本地服务发送 POST 请求。

我尝试使用 XMLHttpRequest 发送请求,但由于跨源限制而失败:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8089/... (Reason: CORS `Access-Control-Allow-Origin' missing).

我读到 here 我可以指定额外的匹配模式以允许在内容脚本中进行跨域访问,但是在将 "http://127.0.0.1:8089/*" 添加到 permissions 之后该限制仍然有效manifest.json.

是否可以克服跨域限制?如果是,怎么做?

根据 wOxxOm's comment under this question,端口号不应出现在匹配模式中。

我将 manifest.json 中的模式更改为 http://127.0.0.1/* 并且可以成功发送请求。