Allowing apps from file:// location to register service workers

429 views
Skip to first unread message

Jiawei Zhang

unread,
Nov 7, 2016, 6:30:20 PM11/7/16
to Chromium-dev
Our app is implemented as local html+javascripts running in a custom-wrapped CEF browser. We have plans to enable push notification using GCM, but found out that file: protocol is not allowed to perform Service Worker registration.

I have tried to modify CEF source to enable it, but simply adding file protocol to serviceWorkerSchemes does not seem to do the trick. When the registration request reach the content layer, the ServiceWorkerProviderHost object created has an empty document_url. All my attempts to fill this field result in bad IPC Message error. Therefore I feel it would be better to find some help from people more knowledgeable on this. Is there some trick to get around this problem?

Thanks all.

Matt Falkenhagen

unread,
Nov 8, 2016, 12:43:42 AM11/8/16
to mrzhangj...@gmail.com, Chromium-dev
I don't know immediately what would prevent this and what trick would solve it, I think you just have to debug until it's working. Adding "file" to serviceWorkerSchemes in ChromeContentClient::AddServiceWorkerSchemes like we do for "chrome-extension" indeed is a good first step. Can you figure out why the provider host document URL is empty and why you're getting a bad IPC message?

I wonder if it could be related to the discussion in this bug about file:// URLs:

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

Jiawei Zhang

unread,
Nov 8, 2016, 3:36:28 PM11/8/16
to Chromium-dev, mrzhangj...@gmail.com
Thanks. Yes that bug is kinda related, but the solution does not apply to my issue.

Update:

A change in origin_util.cc to let OriginCanAccessServiceWorkers and IsOriginSecure return true for file scheme does the trick. Now the new blocking part is: I verified the script file exists on that path, but CEF gives the following error when accessing it:

NET::ERR_INVALID_RESPONSE

Failed to register a ServiceWorker: A bad HTTP response code (-1) was received when fetching the script.
Which I found, was also reported in the electron project here:

https://github.com/electron/electron/issues/2831

Does anyone have clue on this?
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

David Benjamin

unread,
Nov 8, 2016, 3:40:28 PM11/8/16
to mrzhangj...@gmail.com, Chromium-dev
Things like service worker and other features all are tightly connected with the same-origin policy, and file URLs really do not have a viable mapping there. In general, most interesting platform features don't work with file URLs.
Reply all
Reply to author
Forward
0 new messages