[英]Safari extension background page unable to fetch web accessible resource
I have a chrome extension that was converted to Safari extension using xcode safari-web-extension-converter utility.我有一个 chrome 扩展,它使用 xcode safari-web-extension-converter 实用程序转换为 Safari 扩展。 With that, everything except one thing seems to be fine.
这样一来,除了一件事之外的一切似乎都很好。 In the background script, I am loading some data from a web accessible resource like so:
在后台脚本中,我从 web 可访问资源中加载一些数据,如下所示:
export const fetchConfig = async () => {
let dataURL = '';
if (!checkBrowser(BROWSERS.Chrome, true)) {
dataURL = chrome.runtime.getURL('config.json');
} else {
dataURL = browser.runtime.getURL('config.json');
}
const res = await fetch(dataURL);
return await res.json();
}
This works for all browsers except Safari.这适用于除 Safari 之外的所有浏览器。
I am getting the runtime URL as:我得到运行时 URL 为:
safari-web-extension://E522689D-94A6-4561-90F3-BF22C7848965/config.json
safari-web-extension://E522689D-94A6-4561-90F3-BF22C7848965/config.json
but the fetch call fails with the error:但 fetch 调用失败并出现错误:
Failed to load resource: unsupported URL
加载资源失败:不支持 URL
I have not been able to find anything on this in the documentation or the developer support, but can we not access the web accessible resources in background in Safari?我无法在文档或开发人员支持中找到任何相关内容,但我们能否在 Safari 的后台访问 web 可访问资源?
My manifest file looks like this:我的清单文件如下所示:
{
"manifest_version": 3,
"name": "Ext Dev",
"author": "Test",
"description": "Test",
"version": "1.1.0",
"icons": {
"16": "assets/icon/icon16.png",
"32": "assets/icon/icon32.png",
"48": "assets/icon/icon48.png",
"128": "assets/icon/icon128.png"
},
"host_permissions": [
...
host addresses here
...
],
"permissions": ["storage", "tabs"],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self';"
},
"web_accessible_resources": [{
"resources": ["config.json"],
"matches": ["<all_urls>"]
}],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"css": ["commonstyles.css"],
"run_at": "document_end",
"all_frames": true
}
],
"background": { "service_worker": "background.js" },
"action": {
"default_title": "Ext Client",
"default_icon": {
"20": "assets/icon/icon20.png",
"40": "assets/icon/icon40.png"
}
}
} }
I had exactly the same problem as this and discovered in the release notes for Safari 16.0 that they included 'Fixed background service worker to load bundle resources.'我遇到了与此完全相同的问题,并在 Safari 16.0 的发行说明中发现它们包含“固定后台服务工作者以加载捆绑资源”。 Upgrading macOS to 12.6 which comes with safari 16.0 solved this issue for me.
将 macOS 升级到 safari 16.0 随附的 12.6 为我解决了这个问题。 Hopefully this helps!
希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.