Is it possible to make a PWA with Service Workers in Brython? #2180
-
I am building a simple web application. I had wanted to replace Javascript for a long time and so far Brython has been a godsend. But, since it is a progressive web app, I need to register a Service Worker. So far I can only do that in Javascript, is there a way to do that in Brython? I have tried several approaches to no avail : 1 : registering a Brython file using window.navigator.serviceWorker.register(src). 2 : register the Service Worker in javascript, but call Brython functions with the event handlers (onInstall etc.) 3 : communicate with the service worker from Brython code using messages I was able to make a Brython PWA, but only at the cost of writing the Service Worker in Javascript, confining Python to UI. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for raising this issue, and sorry for the late reply. I'm afraid using service workers will not be possible with Brython. The specification makes it explicit that the service worker file must be in Javascript. For web workers, it was possible to convert a Brython script into Javascript, then build a url from a blob containing the JS code and pass it to As you say, the equivalent of |
Beta Was this translation helpful? Give feedback.
Thanks for raising this issue, and sorry for the late reply.
I'm afraid using service workers will not be possible with Brython. The specification makes it explicit that the service worker file must be in Javascript.
For web workers, it was possible to convert a Brython script into Javascript, then build a url from a blob containing the JS code and pass it to
Worker(url)
. For service workers, because of security reasons, the constraint is more strict, the url passed tonavigator.serviceWorker.register(url)
must use the protocol http or https, so I don't think there is a possibility to write the service worker in Python.As you say, the equivalent of
app.js
orimage-list.js
in the service …