重新启动浏览器后,右键菜单消失 [英] Right click menu disappears after restarting the browser
问题描述
我正在开发一个Chrome扩展。我在扩展的右键菜单中添加了一个新的菜单项。它在安装完成后工作正常。然后,当我重新启动浏览器时,新的右键菜单项消失!但是扩展工作正常,只有新的菜单项消失了!
我已经比较了contextMenu的chrome官方示例,看起来是一样的。我只是把创建菜单代码放在chrome.runtime.onInstalled.addListener(function(){})中,就像样例一样.....
任何想法为什么发生这种情况?
非常感谢!
更新:
在清单文件中添加属性:
background:{
persistent:false,
scripts:[background.js]
}
我建议将代码移到一个单独的函数中,然后从 onInstalled
和 chrome.runtime中调用该函数.onStartup
。第一个是在你安装或更新时调用的,第二个是你重新打开浏览器的时候。
I am developing a chrome extension. I have added a new menu item in the right click menu for the extension. It works fine after installed.Then when I restart the browser, the new right click menu item disappears!But the extension work well, only the new menu item is gone! I have compared the chrome official sample for contextMenu, seems the same. I just put the create menu code in chrome.runtime.onInstalled.addListener(function() {}) like the sample does..... Any idea why this happens?
Many thanks!
updated: Add the property in the manifest file: "background": { "persistent": false, "scripts": ["background.js"] }
I would suggest moving the code to a separate function and then calling that function from both onInstalled
and chrome.runtime.onStartup
. The first one is invoked when you install or update, while the second one is when you reopen the browser.
这篇关于重新启动浏览器后,右键菜单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!