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
Share
Improve this question
asked May 21, 2015 at 7:32
Aaron MusktinAaron Musktin
3074 silver badges12 bronze badges
9
-
That's a strange logic to begin with:
executeScript
, then update the tab. What are you achieving here? – Xan Commented May 21, 2015 at 8:00 - @Xan why? I inject jquery.js and my content script, to munite with the DOM, then I want to continue to do something with my popup.js. Above code worked when my tab loaded some web pages, not when the tab is blank. – Aaron Musktin Commented May 22, 2015 at 0:52
- Well, in your simplified code you inject jQuery only, and even then your content script only has time for synchronous operations; anything async will enter a race condition with the tab navigating away and the content script will be wiped as soon as the navigation mits. – Xan Commented May 22, 2015 at 7:24
- @Xan I don't get the async and sync part, are you saying there might be a problem with my flow above? – Aaron Musktin Commented May 22, 2015 at 7:27
- Yes! This is precisely what I'm saying. The content script won't persist after navigation, and has little time to do anything before. Whether it succeeds or not depends on what you're doing. – Xan Commented May 22, 2015 at 7:31
1 Answer
Reset to default 2Normally (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 yourmanifest.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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673799a4639562.html
评论列表(0条)