无法在“WorkerGlobalScope”上执行“importScripts”

use*_*181 1 javascript onesignal progressive-web-apps nuxt.js

我正在尝试在我的 pwa nuxtjs 应用程序中启用 OneSignal 通知。

modules: [
    '@nuxtjs/axios',
    '@nuxtjs/onesignal',
    '@nuxtjs/pwa',
  ],

  oneSignal: {
    cdn: true,
    OneSignalSDK: 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
    init: {
      appId: 'xxxxxxxxxxx',
      allowLocalhostAsSecureOrigin: true,
      welcomeNotification: {
          disable: true
      }
    }
  },
  workbox: {
    dev: true,
    debug: true
  },
Run Code Online (Sandbox Code Playgroud)

我收到弹出通知,当我按下 时Accept,出现以下错误:

获取脚本时收到错误的 HTTP 响应代码 (404)。sw.js?1557093232129:1 未捕获的 DOMException:无法执行

“WorkerGlobalScope”上的“importScripts”:“ http://localhost:3333/_nuxt/workbox.dev.4c4f5ca6.js ”上的脚本加载失败。在http://localhost:3333/sw.js?1557093232129:1:1http://localhost:3333/OneSignalSDKWorker.js?appId=xxxxxxxx:1:1 (匿名)@sw.js?1557093232129:1

ServiceWorkerManager.js:371 [Service Worker Installation] 安装 Service Worker 失败 TypeError: Failed to register a ServiceWorker: ServiceWorker 脚本评估失败

sw.js在静态文件夹中也有该文件。在 Github 问题部分找到了类似的问题,但没有真正的解决方案。

Rod*_*cio 5

Our service workers OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.js overwrite other service workers that are registered with the topmost (site root) service worker scope. The solution is to merge all other service worker scripts into our service worker scripts using importScripts() and to register the merged service worker instead of the original worker.

Both OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.js contain the following code:

importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
Run Code Online (Sandbox Code Playgroud)

Please modify both OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.js to import your other service worker scripts, like:

importScripts('https://example.com/sw.js');
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
Run Code Online (Sandbox Code Playgroud)

We recommend the above approach instead of importing our service worker into another file because our web SDK replaces other workers that are registered on the root scope.

Additionally, please be sure to modify your site's code to register OneSignalSDKWorker.js instead of your own worker. You can do this with code like:

navigator.serviceWorker.register('/OneSignalSDKWorker.js');
Run Code Online (Sandbox Code Playgroud)

Info on service workers