Skip to content Skip to sidebar Skip to footer

Why Is The Response Body Empty (0 Bytes On Network Tab) For This Request? Is It To Do With This Being An Extension?

When I use the fetch API (Or xmlhttprequest) I get a 0 byte response. Here is a sample of my code: fetch('https://myurl', { method: 'POST', headers: { 'Acce

Solution 1:

You need to move all XHR requests to the background part of your extension. Chrome no longer accepts content scripts requests.

You can use runtime.sendMessage to send messages to a background process.

chrome.runtime.sendMessage(myMessageObject, async response => {
  // Here is the response returned by the background process
});

And here is how to receive messages from the background perspective.

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {

  returntrue
})

Solution 2:

I believe you're indeed looking at a CORS issue. Try including the following headers in the response from your server:

Access-Control-Allow-Origin: * // you already hve this one Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS

Post a Comment for "Why Is The Response Body Empty (0 Bytes On Network Tab) For This Request? Is It To Do With This Being An Extension?"