针线serviceworker到处工作,除了铬:未捕获的(以诺)抛出:DOMException

问题描述 投票:2回答:3

针线不工作在Chrome,但它工作在其他地方,这是具有讽刺意味,因为我相信这是一个谷歌图书馆,那就说明是错误:

Uncaught (in promise) DOMException : sw.js line 1

铬:

enter image description here

歌剧enter image description here

火狐enter image description here

我用针线-的WebPack-插件

webpack.config.js

    const workbox = require('workbox-webpack-plugin'); 

    module.exports = {
        plugins: [
            new workbox.GenerateSW({
                swDest: './service-worker.js',
                skipWaiting: true,
                clientsClaim: true
            })
        ]  
 }

index.ts(项)

if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('/js/app/dist/service-worker.js');
  }); 
}

编辑:这是代码抛出错误的行

enter image description here

enter image description here

编辑2:它确实可以工作在隐身模式下,删除浏览器中的数据仍然没有帮助。

enter image description here

编辑3:更新到最新的Beta 1中,更是雪上加霜,因为除了最后一个错误,它会显示一个又一个,但是,此版本适用于Chrome的icognito模式和其他浏览器也。

enter image description here

javascript webpack workbox workbox-webpack-plugin
3个回答
5
投票

如果浏览器已分配的磁盘空间配额通常抛出此错误。无痕是工作,因为它会与新的磁盘配额,在正常的标签共享相同的磁盘配额进行分配。

您可以在devtools打开Application选项卡并单击Clear storage > Clear site data?这应该可以解决在大多数情况下这个问题。

Disk Quota


1
投票

Chrome的自动更新到72版,现在它为我和我的同事。它最可能是一个固定的错误。


0
投票

你可能也有SW文件错误的范围。尝试这个:

if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('/js/app/dist/service-worker.js', { scope: '/' });
  }); 
}

如果你不能移动SW文件,你需要一个特殊的头添加到您的后端:

Server {

    listen www.example.com:443 ssl;

    ...

    location /js/app/dist/service-worker.js {
        add_header 'Service-Worker-Allowed' '/';
    }
}

(nginx的配置)

© www.soinside.com 2019 - 2024. All rights reserved.