我希望在我的扩展程序安装后启动选项。以下是我尝试解决该问题的多种答案。但我遇到的问题是
chrome.runtime.onInstalled
未被定义。下面是我的源代码:background.js。if(typeof chrome.runtime.onInstalled !== 'undefined')
{
chrome.runtime.onInstalled.addListener(function (details)
{
//if(details.reason == 'update') window.open(chrome.extension.getURL('options.html'));
if(details.reason == 'install') window.open(chrome.extension.getURL('options.html'));
});
}
我的manifest.json
{
"name": "Context Menu 2.0 for Google Translate™",
"short_name": "Translate",
"version": "1.0.0.4",
"manifest_version": 2,
"description": "Creates a context menu option to translate selected texts to a specified language",
"icons": {
"16": "trans_16.png",
"64": "trans_64.png",
"128": "trans_128.png"
},
"content_scripts": [
{
"matches":
[
"http://*/*", "https://*/*"
],
"js": ["background.js"]
}
],
"options_page": "options.html",
"background": {
"scripts": ["background.js"]
},
"permissions":[
"http://*/*", "https://*/*",
"storage","contextMenus"
]
}
我在清单文件中漏掉了什么,还是为什么函数没有被定义? 我不得不将检查过程包装起来才能让我的插件正常工作。 否则,我总是会遇到错误,导致脚本停止执行。