gpt4 book ai didi

javascript - Web worker importScripts DOMException 脚本加载失败

转载 作者:行者123 更新时间:2023-11-30 13:54:58 26 4
gpt4 key购买 nike

我正在尝试使用 importScripts

self.addEventListener('fetch', event => {
...
self.importScripts('idb.js');
...
}

为 PWA 的服务 worker 加载库,但不断获取

DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': 
The script at 'http://localhost:3000/idb.js' failed to load.

脚本文件在那里,内容类型正确,application/javascript,我也用 text/javascript 试过了。我的开发人员工具网络选项卡显示请求开始然后很快失败,没有机会访问服务器。通过 http 时,状态代码为 (failed) net::ERR_CONNECTION_REFUSED,通过 https 时,状态代码为 (failed) net::ERR_FAILED。任何帮助表示赞赏

最佳答案

根据 https://developers.google.com/web/updates/2018/10/tweaks-to-addAll-importScripts

Prior to Chrome 71, calling importScripts() asynchronously outside of the install handler would work. Starting with Chrome 71, those calls throw a runtime exception (unless the same URL was previously imported in an install handler), matching the behavior in other browsers.

我必须将 importScripts 移动到我的文件或安装处理程序的顶层,它才有效

关于javascript - Web worker importScripts DOMException 脚本加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57481062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com