Chrome extension open new tab on new tab

前端 未结 2 1610
轻奢々
轻奢々 2020-12-04 02:18

I have created a Chrome extension that, as part of it\'s operation, opens a new tab with a specified url.

chrome.runtime.onMessage.addListener(
  function(r         


        
相关标签:
2条回答
  • 2020-12-04 02:43

    As I was wanting this to run on EVERY page it meant I could not have the code in the content script. I moved all the code into the background script:

    chrome.browserAction.onClicked.addListener(function(tab) {
            //... 
            chrome.tabs.create({"url": newTabUrl});
            //...
    });
    

    So when I click on my button the above code is called, using the enclosed jquery script.

    0 讨论(0)
  • 2020-12-04 03:02

    Well, this message is supposed to come from a content script you're trying to inject into the current tab.

    The widest permission you can request is "<all_urls>", however, there are still URLs that are excluded from access.

    1. You can only normally access http:, https:, file: and ftp: schemes.

    2. file: scheme requires the user to manually approve the access in chrome://extensions/:

    <code>file:</code> access

    1. Chrome Web Store URLs are specifically blacklisted from access for security reasons. There is no override.

    2. chrome:// URLs (also called WebUI) are excluded for security reasons. There is a manual override in the flags: chrome://flags/#extensions-on-chrome-urls, but you can never expect it to be there.

    3. There is an exception to the above, chrome://favicon/ URLs are accessible if you declare the exact permission.

    All in all, even with the widest permissions you cannot be sure you have access. Check for chrome.runtime.lastError in the callback of executeScript and fail gracefully.

    0 讨论(0)
提交回复
热议问题