title: Capacitor Service worker registration unknown error / network connection refused
body: <p>I'm currently working on making a app with <a href="https://capacitor.ionicframework.com/docs/" rel="noreferrer">Capacitor</a> because it uses an internal https server to serve files to the <a href="https://developer.android.com/reference/android/webkit/WebView" rel="noreferrer">WebView</a> instead of the file protocol, this should allow me to use service workers but sadly enough this seems not to be the case, even tho to my understanding everything i'm trying to do is within spec.</p>
  
  <p>main script code:</p>
  
  <pre><code>navigator.serviceWorker.register('sw.js');
  </code></pre>
  
  <p>service worker code:</p>
  
  <pre><code>console.log("I'm a service worker");
  </code></pre>
  
  <p>What i get back</p>
  
  <blockquote>
    <p>An unknown error occurred when fetching the script.
    Failed to load resource: net::ERR_CONNECTION_REFUSED
    localhost/:1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker: An unknown error occurred when fetching the script.</p>
  </blockquote>
  
  <p>What i expect to get back</p>
  
  <blockquote>
    <p>I'm a service worker</p>
  </blockquote>
  
  <p>on the other hand when i just try to fetch the service worker with the exact same request it works fine.</p>
  
  <p>Code:</p>
  
  <pre><code>fetch("https://localhost:4634/sw.js", {
      "credentials":"omit",
      "headers": {},
      "referrer":"https://localhost:4634/sw.js",
      "referrerPolicy":"no-referrer-when-downgrade",
      "body":null,
      "method":"GET",
      "mode":"cors"
  }).then(res =&gt; {
      return res.text();
  }).then(text =&gt; {
      console.log(text);
  });
  </code></pre>
  
  <p>what i get back:</p>
  
  <pre><code>console.log("I'm a service worker");
  </code></pre>
  
  <p>If anyone knows what i'm doing wrong or if this somehow still is out of spec, pleas let me know</p>