扩展图标单击事件不起作用清单版本 3

问题描述 投票:0回答:1

我想在用户单击任何选项卡上的我的扩展图标时监听事件。我做了一些研究,但发现很多操作都被贬值了,我只能找到这个方法,它说它应该有效。

manifest.json

{
    "manifest_version": 3,
    "name": "Messages",
    "version": "1.0",
    "description": "Description of my extension",
    "permissions": ["scripting", "activeTab", "tabs", "tabCapture", "storage", "cookies"],
    "action": {
      "default_popup": "popup.html",
      "default_title": "Click Me"
       
    },

    "externally_connectable": {
      "matches": ["http://localhost:3000/*"],
      "accepts_tls_channel_id": true
    },
    
    
      "background": {
        "service_worker": "background.js"
      },
      "host_permissions": ["<all_urls>"]
    
  }

背景.js

chrome.action.onClicked.addListener(tab => { 
    chrome.tabs.create({
        url: 'popup.html'
      });

      console.log('cow')
     });

当我单击站点上的扩展图标时,没有任何反应,我通过转到 chrome 扩展设置并找到我的扩展来检查服务器工作人员的控制台日志,那里没有记录任何内容。

监听扩展点击事件的有效解决方案是什么

javascript google-chrome google-chrome-extension onclick
1个回答
0
投票

如果清单中有

default_popup
设置,它将覆盖 onClicked 事件侦听器。删除该行应该允许事件触发并在新选项卡中打开
popup.html
文件。

© www.soinside.com 2019 - 2024. All rights reserved.