ImportScript因Safari Web扩展而失败

发布于 2025-02-10 20:43:38 字数 776 浏览 1 评论 0 原文

我正在将有效的V3 Chrome扩展程序移植到MacOS上的Safari。在我的背景(服务工作者)脚本中,我调用

self.importscripts(“ platform.js”);

应该加载上述JavaScript文件。它与称呼它的脚本相同。

但这在Safari(不是Chrome)中失败了:

无法加载资源:不支持的URL Safari-web-Extension://fe580c4d-9931-4639-4639-abf9-.../platform.js

(点替换为最后一个HEX数字)。在宣言中,我有台词:

"web_accessible_resources": [
    {
      "resources": ["Platform.js"],
      "matches": ["<all_urls>"]
    },...

我正在按照。我正在经营Macos Monterey,Safari 15.5。

关于我可能需要尝试的任何指示,都将不胜感激。我想到静态导入代码,但这不是JavaScript模块。

I'm porting a working v3 chrome extension to Safari on MacOS. In my background (service worker) script I call

self.importScripts("Platform.js");

which should load said JavaScript file. It's in the same folder as the script that calls it.

But this fails in Safari (not chrome) with the error:

Failed to load resource: unsupported URL safari-web-extension://FE580C4D-9931-4639-ABF9-...../Platform.js

(dots substituted for the last hex digits). In the manifest I have the lines:

"web_accessible_resources": [
    {
      "resources": ["Platform.js"],
      "matches": ["<all_urls>"]
    },...

I'm following the instructions for converting a web extension to Safari. I'm running MacOS Monterey, Safari 15.5.

Any pointers as to what I might need to try would be appreciated. I thought of statically importing the code but it's not a JavaScript module.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫九 2025-02-17 20:43:38

与清单V3和Safari 16.1有相同或相似的问题。首先,请确保所有代码(.js,.html,.css)都包含在“构建阶段”上的代码签名中::

构建阶段

接下来,我尝试使用模块支持。 清单

"background": {
        "service_worker": "background.js",
        "type" : "module"
    },

"background": {
    "page" : "background.html"
},

<script type="module" src="background.js"></script>

import * as common from "./common.js";

Had the same or similar issue with manifest v3 and safari 16.1. First, be sure that all the code (.js, .html, .css) are included in the build for code signing on "Build Phases"::

Build Phases

Next, I was trying to use module support. In the manifest.json, i removed the :

"background": {
        "service_worker": "background.js",
        "type" : "module"
    },

and replaced it with:

"background": {
    "page" : "background.html"
},

the background.html then is a simple:

<script type="module" src="background.js"></script>

the background.js then uses an import on the first line as:

import * as common from "./common.js";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文