简体   繁体   English

Firefox扩展内容脚本无法请求XMLHttpRequest

[英]Firefox extension content script cannot request XMLHttpRequest

According to the Firefox Content Script ,the XMLHttpRequset can be used. 根据Firefox内容脚本 ,可以使用XMLHttpRequset。

I have tried both XMLHttpRequest and Api Fectch.It only responses with error message. 我已经尝试了XMLHttpRequest和Api Fectch.It只响应与错误消息。 I already disable CORS on the server.It still dosen't work. 我已经在服务器上禁用了CORS。它仍然无法正常工作。

I run Django local server on the computer. 我在计算机上运行Django本地服务器。

This is the code: 这是代码:

function getWord(word){
   var req = new XMLHttpRequest();
   req.open("GET", "http://127.0.0.1:8000/api/${word}/",true);
   req.onload = function(){
      console.log("done");
   }
   req.onerror = function(){
      console.log("error : ",this.error);
   }
   req.send();

Console error: 控制台错误:

error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, loaded: 0, total: 0, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, … }

It work on other files(Not extension). 它适用于其他文件(不扩展名)。

Problem solve 问题解决

The problem is that I forgot to set the permission in the manifest.json. 问题是我忘记在manifest.json中设置权限。

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions https://developer.mozilla.org/zh-CN/Add-ons/WebExtensions/manifest.json/permissions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM