Experience-Monks / devtool

[OBSOLETE] runs Node.js programs through Chromium DevTools
MIT License
3.77k stars 150 forks source link

Can't register a serviceWorker #65

Open jcansdale opened 8 years ago

jcansdale commented 8 years ago

I'd like to be able to register a service worker: navigator.serviceWorker.register('/sw.js');

Access to service workers is denied in this document origin.

Is looks like there is a function that can be called to override this, but I'm not sure where it needs to be called from: registerURLSchemeAsAllowingServiceWorkers("file");

According to this issue, this should be enabled by default from Electron v0.36.0: https://github.com/electron/electron/issues/2831

Is there any way to get this working with the current bits?

mattdesl commented 8 years ago

I've tried adding that code to server.js and preload.js and I'm still getting an error using ServiceWorkers. Seems like an Electron bug?

GET file:///projects/jam3npm/devtool/test/fixtures/service-worker.js net::ERR_INVALID_RESPONSE
undefined:1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker: A bad HTTP response code (-1) was received when fetching the script.
mattdesl commented 8 years ago

See test here: https://github.com/Jam3/devtool/tree/test-service-worker

jcansdale commented 8 years ago

Looking at the Chromium C++ code: https://codereview.chromium.org/1191793003/diff/40001/Source/platform/weborigin/SchemeRegistry.cpp if (serviceWorkerSchemes.isEmpty()) { serviceWorkerSchemes.add("http"); serviceWorkerSchemes.add("https"); serviceWorkerSchemes.add("chrome-extension");

I wonder if: electron.protocol.registerServiceWorkerSchemes(['file:']);

...should use simply 'file'? This is very much a guess! :)

Thanks for looking into it!

mattdesl commented 8 years ago

Can you try 2.0.2? It should have a patch for this.

To update:

npm install devtool -g
mattdesl commented 8 years ago

Ok, nevermind. Error is still there