fetch: TypeError: NetworkError when attempting to fetch resource - firefox issue

Hi, I have simple function for logout that looks like this

public logoutHandler() {
    fetch('/logout', <RequestInit>{
      method: 'get',
      credentials: 'include'
    }).then((response) => {
      console.log(document.cookie);
      window.location.href = '/login';
    });
  }

It is workin in chrome but in firefox I get “TypeError: NetworkError when attempting to fetch resource.1 (unknown)”. Client side app is on the same server as backend, I’m using https connection with self-signed cert, could it be the issue?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 23
  • Comments: 22 (1 by maintainers)

Most upvoted comments

On chrome, I’ve got “TypeError: Failed to fetch” On firefox, the same “TypeError: NetworkError when attempting to fetch resource” …

Can we reopen this ticket? I’m seeing the same error, but only on Firefox. Also, nothing shows up in the Network tab.

For those who are writing Firefox addon, the solution here helped me, I have to add "*://localhost/*" to permissions key in manifest.json:


  "permissions": [
    "storage",
    "*://localhost/*"
  ],

Chrome just works without the need to add this permission…

Have you check errors like CORS?

@ariden83 did you figure out what was causing the errors? I’m seeing the same issues in isolated cases

Check if you are using http or https on your server. For me, the error was coming online with heroku server because they use https while in local machine I was using http and it was working. After choosing https on Heroku for my endpoints, it also worked

In our case, the solution was not using the wild card for Access-Control-Allow-Origin on the server side, instead of the wild card, our settings look like this:

res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader("Access-Control-Allow-Headers", "Authorization, Cache-Control, Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");

Having the same issue when I have network.http.referer.XOriginPolicy set to 1 (“send a referrer only when the base domains are the same”). Is that supposed to happen? I’m quite sure the base domain of localhost matches the base domain of itself 😃

I’m seeing the same error,except chrome

I managed to solve the problem by monitoring the headers returned by github used on the demo page.
Since I’m using a python webserver, they look something like this:

self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
self.send_header("Access-Control-Allow-Headers", '*');
self.send_header("Status", "200 OK")
self.send_header("Vary", "Accept")
self.send_header('Content-Type', 'application/octet-stream')

Hope it helps.

Firefox contains a native fetch implementation and does not use this polyfill code. You can use the Network tab in Firefox’s web console to debug the request and response.