【发布时间】:2011-08-03 14:24:27
【问题描述】:
我想通过单击浏览器操作按钮创建一个选项卡,然后插入内容脚本或执行脚本。到目前为止,它的效果并不好。
背景.html
chrome.browserAction.onClicked.addListener(function(tab)
{
chrome.tabs.create({url: "Dreamer.html"}, function(tab) //Dreamer.html is a file in my extension
{
//Add a script
chrome.tabs.executeScript(tab.id, {file:'Dreamer.js'});
});
});
Manifest.json
{
"name" : " Dreamer",
"version" : "0.1",
"description" : "My extensionr",
"browser_action" : {"default_icon" : "App/AppData/Images/icon.png", "default_title":"Start Dreamer" },
"background_page" : "App/AppData/background.html",
"content_scripts" :[{"matches":["http://*/*"],"js":["app/view/UIManager.js"]}],
"permissions": [ "cookies", "tabs", "http://*/*", "https://*/*" ]
}
我在后台页面收到此错误
Error during tabs.executeScript: Cannot access contents of url "chrome-extension://femiindgnlfpdpajimkmldpgpccngfmd/Dreamer.html". Extension manifest must request permission to access this host.
我真的很想知道如何创建一个标签(新标签)并立即运行一个脚本
编辑:
我正在创建的应用程序类型需要以下操作:
-允许用户通过点击 browserAction 按钮创建新标签
- 在创建新选项卡时,我的扩展程序 (Dreamer.html) 中的一个文件被打开
-在新标签页中添加内容脚本或执行脚本
谢谢
【问题讨论】:
标签: google-chrome permissions tabs