Reputation: 307
chrome.tabs.executeScript(null, { file: "jquery.js" }, function() {
chrome.tabs.update(null, {url: 'https://example.com/'});
});
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
Upvotes: 4
Views: 9921
Reputation: 73526
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.com/_/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.com/_/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.
Upvotes: 2