0

My Request looks as follows:(obviously with a different url, which is different from the visited page)

var url = "https://example.com/example.json" 
var request = new XMLHttpRequest()

request.onreadystatechange = function () {
    if (this.readyState == 4 || this.status == 200) {
        console.log(this.readyState, this.status)
        var arr = JSON.parse(this.response)

        // Do stuff with the response...
    }
};

request.open("GET", url)
request.send()

In Chrome it always works. In Firefox it works when i execute it in the popup.js of the Addon (included in the extension popup.html, but it doesnt work in the content script, what? :o

From the Console Log im getting Status 0 when its executed from the content script.

Is there any small workaround to make it work? I mean isnt this just very basic stuff...? I also tried Javascript fetch, but there i have the exact same Problem.... :/

H. Beck
  • 11
  • 6
  • Send a message to the background script and do the fetch there, [example](https://stackoverflow.com/a/55292071). – wOxxOm Feb 26 '21 at 10:44
  • @wOxxOm Im now using an Alarm in the background script to periodically fetch the JSON now, thank you :) – H. Beck Feb 26 '21 at 12:40

0 Answers0