[英]How to run a chrome extension from a click button?
After a lot of times spend to find the solution, i'm here to ask your help.在花了很多时间寻找解决方案之后,我在这里寻求您的帮助。
I have a simple chrome extension, and what I try to do is simple: Detect on the page when a button is clicked, then, open the extension popup.html
.我有一个简单的 chrome 扩展程序,我尝试做的很简单:单击按钮时在页面上检测,然后打开扩展程序popup.html
。
A good example is MetaMask, the html page can open the popup to connect the wallet, send transaction...一个很好的例子是 MetaMask,html 页面可以打开弹出窗口连接钱包,发送交易......
Thank you !谢谢 !
// Content Script button.addEventListener("click", () => { chrome.runtime.sendMessage("OpenPopup") })
// Background Script chrome.runtime.onMessage.addListener(request => { if (request == "OpenPopup") { chrome.windows.create({ url: "popup.html", type: "popup", focused: true, width: 400, height: 600, top: 0, left: screen.width - 400, }, () => { console.log("Opened popup!") }) } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.