几分钟后,服务人员停止聆听Chrome.action。如何处理?
我试图将扩展名迁移从subtestv2到subestv3。该扩展程序的一个方面之一是,用户应该能够单击扩展图标以在当前网页上执行特定操作。
因此,我在我的 background.js 中都有此代码:
chrome.action.onClicked.addListener((tab) => {
console.log('action On Clicked')
chrome.tabs.sendMessage(tab.id, "toggle");
})
但是,在同一网页上几分钟后,扩展按钮不再起作用,并且侦听器回调函数未调用(“操作”单击“未在控制台中打印”。
我想知道我在这里是否想念一些小事?如何实现此简单需求:通过单击扩展名的主按钮在当前网页上触发事件?
I am trying to migrate an extension from ManifestV2 to ManifestV3. One of the aspects of this extension is that the user should be able to click on the extension icon to perform a particular action on the current webpage.
So, I have this code in my background.js:
chrome.action.onClicked.addListener((tab) => {
console.log('action On Clicked')
chrome.tabs.sendMessage(tab.id, "toggle");
})
However, after a few minutes on the same webpage, the extension button is not working anymore, and the listener callback function is not called ("action On Clicked" is not printed in the console).
I wonder if I miss something trivial here? How to implement this simple need: trigger an event on the current webpage by clicking the main button of the extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论