每次点击 Chrome 扩展程序图标时运行脚本 [英] Run script each time Chrome extension icon clicked

查看:23
本文介绍了每次点击 Chrome 扩展程序图标时运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写 chrome 扩展程序,以便每次用户单击图标时,我的脚本都会运行但不打开弹出窗口?(我会自己在文档中查找这个,但无论出于何种原因,他们突然停止工作,每个页面都 404,因为我到了这一点).

How do I write a chrome extension such that every time a user clicks the icon, my script is run but no popup is opened? (I would look this up in the docs myself but for whatever reason they suddenly stopped working, 404ing every page, as I got to this point).

我假设它只是正确设置了清单.这是我现在所拥有的:

I'm assuming it's just setting up the manifest correctly. Here's what I have now:

{
  "name": "My Extension",
  "version": "0.1",
  "description": "Does some simple stuff",
  "browser_action": {
    "popup" : "mine.html",
    "default_icon": "logo.png"
  },
  "permissions": [
    "notifications"
  ]
}

推荐答案

从清单的 browser_action 部分移除弹出窗口并使用 背景页面 以及后台脚本中的浏览器操作.

Remove popup from your browser_action section of the manifest and use background pages along with browser Action in the background script.

chrome.browserAction.onClicked.addListener(function(tab) { alert('icon clicked')});

这篇关于每次点击 Chrome 扩展程序图标时运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆