0

我尝试构建一个 Safari 应用程序扩展。javaScript popup.js 不会针对工具栏图标运行。popup.html 显示正确。

popup.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="popup.js"></script>
    <link rel="stylesheet" href="popup.css">
</head>
<body>
    <strong>Hello World!</strong>
</body>
</html>

popup.js

alert("Test");

清单.json

{
    "manifest_version": 2,
    "default_locale": "en",

    ...


    "background": {
        "scripts": [ "background.js" ],
        "persistent": true
    },

    ...
    
    "browser_action": {
        "default_popup": "popup.html",
        "default_icon": {
            "16": "images/toolbar-icon-16.png",
            "19": "images/toolbar-icon-19.png",
            "32": "images/toolbar-icon-32.png",
            "38": "images/toolbar-icon-38.png"
        }
    },

    "permissions": ["notifications",
        "create",
        "tabs"]
}

4

1 回答 1

0

我通过移动<script src="popup.js"></script>身体部分解决了这个问题:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="popup.css">
</head>
<body>
    <strong>Hello World!</strong>
    <script src="popup.js"></script>
</body>
</html>
于 2021-12-10T12:58:15.717 回答