仍然找不到硬编码清单开始 url?

saz*_*azr 1 wordpress manifest progressive-web-apps

我正在尝试将 WordPress 主题设置为渐进式 Web 应用程序。当我运行 Chromes 审核工具(灯塔?)时,我收到一个无信息的错误,我不知道问题到底是什么。错误是:

失败:Service Worker 未成功提供清单 start_url。无法通过 Service Worker 获取开始 url

我已经硬编码了我的起始网址,这是一个有效的网址。关于问题可能是什么的任何建议吗?

https://mywebsite.com/wp-content/themes/mytheme/web.manifest

  ...
  "scope": "/",
  "start_url": "https://mywebsite.com",
  "serviceworker": {
    "src": "dist/assets/sw/service-worker.js",
    "scope": "/aw/",
    "update_via_cache": "none"
  },
  ...
}
Run Code Online (Sandbox Code Playgroud)

https://mywebsite.com/wp-content/themes/mytheme/dist/assets/sw/service-worker.js

...
// The fetch handler serves responses for same-origin resources from a cache.
// If no response is found, it populates the runtime cache with the response
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
  // Skip cross-origin requests, like those for Google Analytics.
  if (event.request.url.startsWith(self.location.origin)) {
    event.respondWith(
      caches.match(event.request).then(cachedResponse => {
        if (cachedResponse) {
          return cachedResponse;
        }

        return caches.open(RUNTIME).then(cache => {
          return fetch(event.request).then(response => {
            // Put a copy of the response in the runtime cache.
            return cache.put(event.request, response.clone()).then(() => {
              return response;
            });
          });
        });
      })
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

我使用以下代码注册我的软件,并输出它已成功注册软件:

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register(Vue.prototype.$ASSETS_PATH + 'sw/service-worker.js')
  .then(function(registration) {
    console.log('Registration successful, scope is:', registration.scope);
  })
  .catch(function(error) {
    console.log('Service worker registration failed, error:', error);
  });
}
Run Code Online (Sandbox Code Playgroud)

Jos*_*ian 8

请将您的 start_url 更改为

 "start_url": "/"
Run Code Online (Sandbox Code Playgroud)

它必须是相对 URL。请参阅文档

在此输入图像描述