I built a simple flutter web app. It works fine on github.io and also on the localhost
server:
$ flutter run -d chrome
If I create a release build:
$ flutter build web
turning the app into (basically) a JavaScript file (main.dart.js
), why can't I just run the app by loading the created index.html
file?
The JavaScript debugger in my browser tells me this code:
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
produces the error:
Uncaught (in promise) TypeError: ServiceWorkerContainer.register: Script URL's scheme is not 'http' or 'https'
I'm not sure what this means or how to fix it. I know it's not as simple as just adding http
in front of flutter_service_worker.js
.