小编Jho*_*hon的帖子

chrome.runtime.onMessage 多次调用

我创建一个扩展。当用户单击扩展图标时,它将向内容脚本发送消息,然后内容脚本再次调用函数。在该函数中,它将向后台脚本发送消息。我在后台脚本执行多次时遇到一些奇怪的行为 chrome.runtime.onMessage.addListener() 。

清单.json

{
    "manifest_version": 2,
    "name": "Reportar",
    "version": "1.0",
    "description": "Loreipsum.",
    "background": {
        "scripts": ["bootstrap.js"],
        "persistent": false
    },
    "browser_action": {
        "default_icon": "img/icon48.png",
        "default_title": "Gitlab Issue"
    },
    "web_accessible_resources": [
        "templates/*.html"
    ],
    "content_scripts": [{
            "all_frames": false,
            "css": ["content_style.css"],
            "js": ["content_script.js"],
            "matches": ["http://*/*", "*/*"]
        }],
    "icons": {
        "16": "img/icon20.png",
        "48": "img/icon48.png",
        "128": "img/icon128.png"
    },
    "permissions": [
        "tabs",
        "activeTab",
        "<all_urls>",
        "storage"
    ]
}
Run Code Online (Sandbox Code Playgroud)

背景.js

function clickOnIssue() {
    chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
        console.log('Going to send message to content script that …
Run Code Online (Sandbox Code Playgroud)

google-chrome-extension

3
推荐指数
1
解决办法
3934
查看次数

标签 统计

google-chrome-extension ×1