electron: [Bug]: ServiceWorker cannot cache custom scheme URLs

Preflight Checklist

Electron Version

v19.0.9

What operating system are you using?

Other Linux

Operating System Version

Gentoo

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Register custom scheme:

electron.protocol.registerSchemesAsPrivileged([
  {
    'app',
    privileges: {
      standard: true,
      secure: true,
      allowServiceWorkers: true,
      bypassCSP: true,
      supportFetchAPI: true,
      corsEnabled: true,
      stream: true,
    },
  },
])

In the Service Worker:

const cache = await self.caches.open('myCache')
const response = await fetch(request)
cache.put(request, response)

Expected that the cache can store the URL.

Actual Behavior

With the url app://index.html/b/test the fetch works perfectly but cache.put returns an error:

TypeError: Failed to execute 'put' on 'Cache': Request scheme 'app' is unsupported

Testcase Gist URL

No response

Additional Information

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 6
  • Comments: 22 (5 by maintainers)

Most upvoted comments

🪄 unstale

bump

Bump and this stale bot is counterproductive.

@MarshallOfSound I think that it’s relatively safe to add cacheing of alternate handlers specific to electron.

The protocol handler already registers schemas as privileged - it would be useful to add another flag to the privileged list like isConsideredHttpFamily or even more strictly cacheable

  const customSchemes = ["file", "internal-schema"].map((s) => ({
    scheme: s,
    privileges: {
      secure: true,
      standard: true,
      allowServiceWorkers: true,
      stream: true,
      bypassCSP: true,
      corsEnabled: true,
      supportFetchAPI: true,
    },
  })) as CustomScheme[];

This would just allow service workers to cache these assets, which would be pretty nice

I don’t know why it would be necessary to block caching non-http schemes. Maybe the original check was thinking that the only non-http scheme a browser would see is a file:// scheme, or similar.