0
votes

According to the Firefox Content Script,the XMLHttpRequset can be used.

I have tried both XMLHttpRequest and Api Fectch.It only responses with error message. I already disable CORS on the server.It still dosen't work.

I run Django local server on the computer.

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).

1
Are you sure that your URL resolves normally, and that the word variable is populated correctly? Check your browser's network tab. - CertainPerformance
I'll edit.The word is the parameter of the function. - O.Chounry
that error isn't helpful at all - what is the actual error itself, you seem to have ... instead of the useful message ... I already disable CORS - why? - Jaromanda X
It shows only that error.If I don't put the req.onerror It dosen't show anything. - O.Chounry
Are you sure you have webRequest in your extension's permissions? developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/… - squgeim

1 Answers

0
votes

Problem solve

The problem is that I forgot to set the permission in the manifest.json.

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