Chrome Extension - permissions for executing code on new tab
I have following code for opening new tab with defined URL 开发者_如何学Cand then execute some piece of code on it:
chrome.tabs.create({
'url': 'https://myownServer.com',
'selected': false
}, function(tab) {
chrome.tabs.executeScript(tab.id, {
'file': 'myCode.js'
});
});
The tab openes, but when it comes to execute the file (myCode.js), it log to console this error:
Uncaught Error: You do not have permission to use 'tabs.executeScript'.
Be sure to declare in your manifest what permissions you need.
I have not found any permission like this (except 'tabs', which i'm already having in my manifest.json). What should I do to make it work?
You need to declare host permissions that would allow you to inject content scripts on qualified domains:
"permissions": [
"tabs", "https://myownServer.com/*"
],
more about it here and here.
精彩评论