Regressed Cross-site XMLHttpRequest is blocked if Service Worker is used without fetch event handler

Published: | Categories: DOM, Networking

Description

Firefox 44 has introduced a regression regarding XMLHttpRequest and Service Workers where cross-site HTTP requests don’t work properly when the site has a Service Worker and it’s not handling the fetch event. When this issue occurs, the Origin header is missing in GET requests, resulting in an unnecessary preflight OPTIONS request and subsequent failed GET request. The bug has been fixed with Firefox 45. The workaround for Firefox 44 is adding a simple event listener to the worker code like this:

self.addEventListener('fetch', function(event) {
  event.respondWith(fetch(event.request));
});

Update: Clarified the condition that involves the Service Worker API and added the workaround, according to the bug comments.

References