Description
Bug report
The service worker not work with webpack DevServer also when dev-server is configure in write memory like specify in :
(https://webpack.js.org/configuration/dev-server/) writes in-memory
Actual Behavior
The service worker is register and activated but event are never trigger. no error
Expected Behavior
Event of service worker should be trigger
How Do We Reproduce?
- Register your service worker :
if ('serviceWorker' in navigator) {
try {
var registration = await navigator.serviceWorker.register('/sw.js', { scope: './' });
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
console.log('installing : ' + serviceWorker.state);
} else if (registration.waiting) {
serviceWorker = registration.waiting;
console.log('waiting : ' + serviceWorker.state);
} else if (registration.active) {
serviceWorker = registration.active;
console.log('active : ' + serviceWorker.state);
}
} catch (err) {
console.error(err);
}
}
else {
console.error('Service workers are not supported.');
}
- sw.js
self.addEventListener('install', event => { console.log('Hello'); });
with other web server you will have in the console :
active : activated
Hello
but with dev-server only
active : activated
Please paste the results of npx webpack-cli info
here, and mention other relevant information
"webpack": "5.74.0",
"webpack-dev-server": "4.10.0"
const serverConfig = { client: { overlay: false, logging: 'error', }, devMiddleware: { writeToDisk: true, }, open: false, https: false, host: '127.0.0.1', port: 5800, hot: true, liveReload: false, static: { directory: path.join(__dirname, 'dist/'), } };