Chrome extension open new tab on new tab -
i have created chrome extension that, part of it's operation, opens new tab specified url.
chrome.runtime.onmessage.addlistener( function(request, sender, sendresponse) { if( request.message === "open_new_tab" ) { chrome.tabs.create({"url": request.url}); } } );
(full code available on github)
this works fine on tabs webpages, cannot work on empty tabs, example: chrome://apps/
clarify, if have tab open , on stackoverflow.com, when click on extension button opens new tab loading generated url. when on new tab, or tab url begins chrome://
extension not work.
what permissions need include allow extension open in tab? including new tabs , chrome://
tab?
manifest.json:
{ "manifest_version": 2, "name": "myminicity checker", "short_name": "myminicity checker", "description": "checks city needs , redirects browser accordingly.", "version": "0.2", "author":"richard parnaby-king", "homepage_url": "https://github.com/richard-parnaby-king/myminicity-checker/", "icons": { "128": "icon-big.png" }, "options_page": "options/options.html", "browser_action": { "default_icon": "icon.png" }, "permissions": ["tabs","storage","http://*.myminicity.com/","http://*/*", "https://*/*"], "background": { "scripts": ["background.js"], "persistent": false }, "content_scripts": [ { "matches": [ "http://*/*", "https://*/*"], "js": [ "jquery-1.11.3.min.js" ] }] }
background.js:
//when user clicks on button, run script chrome.browseraction.onclicked.addlistener(function(tab) { chrome.tabs.executescript(null, { file: "jquery-1.11.3.min.js" }, function() { chrome.tabs.executescript(null, { file: "contentscript.js" }); }); }); chrome.runtime.onmessage.addlistener( function(request, sender, sendresponse) { if( request.message === "open_new_tab" ) { chrome.tabs.create({"url": request.url}); } } );
it appears though background.js file not being executed. suspect permissions. permissions need in order run extension in every tab?
well, message supposed come content script you're trying inject current tab.
the widest permission can request "<all_urls>"
, however, there still urls excluded access.
you can access
http:
,https:
,file:
,ftp:
schemes.file:
scheme requires user manually approve access inchrome://extensions/
:
chrome web store urls are blacklisted access security reasons. there no override.
chrome://
urls (also called webui) are excluded security reasons. there manual override in flags:chrome://flags/#extensions-on-chrome-urls
, can never expect there.there exception above,
chrome://favicon/
urls accessible if declare exact permission.
all in all, widest permissions cannot sure have access. check chrome.runtime.lasterror
in callback of executescript
, fail gracefully.
Comments
Post a Comment