chrome.tabs.executeScript(null, { file: "jquery.js" }, function() {
chrome.tabs.update(null, {url: '/'});
});
above code work when I trigger when my address bar have something, means I'm at any web pages, but when I trigger when my address bar is blank, I got below error :
Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL
at Object.callback
chrome.tabs.executeScript(null, { file: "jquery.js" }, function() {
chrome.tabs.update(null, {url: 'https://example./'});
});
above code work when I trigger when my address bar have something, means I'm at any web pages, but when I trigger when my address bar is blank, I got below error :
Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL
at Object.callback
executeScript
, then update the tab. What are you achieving here?
– Xan
Commented
May 21, 2015 at 8:00
Normally (see also Programmatic Injection in docs) it's not possible to inject scripts into tabs with chrome://
urls because the allowed schemes are <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp'
.
In Chrome before v61 it was still possible to inject into the content frame of the New Tab page, where the "blank address bar" you mentioned is represented internally as chrome://newtab/
. For example the main frame has an address like this: https://www.google./_/chrome/newtab?espv=2&es_th=1&ie=UTF-8 (use Network panel in devtools to inspect the urls). So your manifest.json
would have "permissions": ["tabs", "https://www.google./_/chrome/newtab*"],
Alternatively you can enable chrome://flags/#extensions-on-chrome-urls
flag, however this is hardly useful as Chrome will show a warning each start.