google chrome - How can i create a new tab via browserAction and then execute a script -
i want create tab clicking on browser action button , insert content script or execute script. far, not working well.
background.html
chrome.browseraction.onclicked.addlistener(function(tab) { chrome.tabs.create({url: "dreamer.html"}, function(tab) //dreamer.html file in extension { //add 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://*/*" ] } i error in background page
error during tabs.executescript: cannot access contents of url "chrome-extension://femiindgnlfpdpajimkmldpgpccngfmd/dreamer.html". extension manifest must request permission access host. i know how create tab(new tab) , run script immediately
edit:
the kind of application creating requires following actions:
-allow user create new tab clicking browseraction button
-on creation of new tab, file in extension (dreamer.html) opened
-add content script or execute script in new tab
thanks
is there particular reason need inject script? since both dreamer.html , dreamer.js seem hardcoded, include <script type="text/javascript" src="dreamer.js"></script> in former, right?
as side benefit, if need send info background page, can access directly chrome.extension.getbackgroundpage() instead of setting complex listeners come content scripts, too.
injecting content scripts injecting scripts outside extension sandbox. dreamer.html, however, part of extension.
edit
if want (unwieldy) example of how execute script in extension page, see here:
http://code.google.com/p/chromium/issues/detail?id=30756#c11
i don't think applies case, however.
Comments
Post a Comment