Mas*_*gar 7 javascript google-chrome-extension
我正在尝试编写Google Chrome扩展程序.
该文件甚至示例代码说一个背景页可以使用活动选项卡上运行JavaScript chrome.tabs.executeScript的方法,但chrome.tabs始终是undefined当我在调试器打破.
这种行为在我的代码和Google示例代码中都很明显.
真实问题:如何在Chrome扩展程序中的后台页面上的活动标签页上运行JavaScript?
background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
debugger;
// chrome.tabs is undefined here
chrome.tabs.executeScript({
code: "console.log('hi')"
});
});
Run Code Online (Sandbox Code Playgroud)
manifest.js:
{
"manifest_version": 2,
"name": "Hello World",
"description": "Says 'hello' to the world.",
"version": "0.1",
"permissions": ["tabs", "activeTab"],
"browser_action": {
"default_title": "hi"
},
"background": {
"scripts": ["background.js"]
}
}
Run Code Online (Sandbox Code Playgroud)
我试过的事情:
persistent在标志background在清单文件中false,true,"false",和"true""tabs"许可我尝试访问时运行时抛出此错误chrome.tabs:
Lazy require of tabs.binding did not set the binding field
| 归档时间: |
|
| 查看次数: |
1202 次 |
| 最近记录: |