'serviceWorker on LAMP doesn't exist
I'm testing serviceWorker according "https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers"
My PC with Ubuntu 18.04, apache2 v2.4.29, Firefox 69.0.1
I saw that serviceWorker functions only on HTTPS domains but also, for testing, on port 80 and localhost.
I test it on one of my test domains, outilsrouteur.test, where /etc/apache2/sites-available/outilsrouteur.test.conf is:
<VirtualHost *:80>
ServerName outilsrouteur.test
ServerAlias www.outilsrouteur.test
DocumentRoot ***/siteoutilsrouteur // *** = my real directory
<Directory ***/siteoutilsrouteur> // *** = my real directory
DirectoryIndex index.html index.php
Options SymLinksIfOwnerMatch
AllowOverride all
Require local
</Directory>
ErrorLog ***/siteoutilsrouteur/error.log.txt
CustomLog /access.log combined
</VirtualHost>
and etc/apache2/port.conf is:
Listen 80
I have barely modified app.js as:
console.log("===================\napp.js :\n\n"); //****
if ('serviceWorker' in navigator) {
console.log("serviceWorker existe");
navigator.serviceWorker.register('./sw-test/sw.js', {scope: './sw-test/'})
.then((reg) => {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch((error) => {
// registration failed
console.log('Registration failed with ' + error);
});
} else { //****
console.log("serviceWorker n'existe pas / doesn't exist : '"+location.port+"'"); //****
}
I Thought that my LAMP works listening port 80, but, when I call my test page (first step):
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>SW map</title>
<body>
<h1>Pour voir</h1>
<section></section>
<script src="app.js"></script>
</body>
</html>
the console show these messages:
===================
app.js :
app.js:1:9
serviceWorker n'existe pas / doesn't exist : ''
So, my test run, but the location port isn't 80 and no serviceWorker exists...
Could you please show me my mistake(s)?
Solution 1:[1]
Ok, down on bottom of mdn page :
When testing you can get around the HTTPS restriction by checking the "Enable Service Workers over HTTP (when toolbox is open)" option in the Firefox Developer Tools settings.
It does function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Roland Gautier |