Does content_scripts matches “chrome-extension://*/*” work?

后端 未结 4 1361
终归单人心
终归单人心 2020-11-28 15:09

I want to run a content script on an iframe with a chrome-extension:// URL. I added a line to my manifest.json that I copied out of the documentation http://code.google.com/

相关标签:
4条回答
  • 2020-11-28 15:54

    I'm having the exact same problem, look at the API http://code.google.com/chrome/extensions/match_patterns.html it says clearly that they accept chrome-extension://*/* yet they don't.

    They need to update the API so as not to confuse people.

    0 讨论(0)
  • 2020-11-28 16:00

    You can inject js to your iframe html(chrome-extension: pages) without declaring it in manifast.json. The injected js can visit Chrome APIs directly.

    iframe.html:

    <!DOCTYPE html>
    <html>
    <head>
    ...
    </head>
    <body>
    ...
    </body>
    <script src="iframe.js"></script>
    </html>
    

    iframe.js:

    console.log(chrome); // {loadTimes: ƒ, csi: ƒ, …}
    
    0 讨论(0)
  • 2020-11-28 16:12

    It seems that Chrome authors have silently removed the ability for content scripts to be injected into chrome-extension: pages. Documentation still says that it works and even contains examples with chrome-extension: scheme but actually it doesn't work. So now only http:, https: and ftp: work "from the box" and file: can work if user of your extension has enabled this on Extensions (chrome://extensions/) page.

    Update: now documentation referred above is updated and says nothing about ability to inject content scripts to chrome-extension: pages.

    0 讨论(0)
  • 2020-11-28 16:13

    No. Only ftp:, file:, http: and https: can be matched by a content script declaration.

    Invalid URL patterns at any of the matches and exclude_matches fields are rejected (generating an error when trying to load the extension).

    Invalid patterns at the permissions option in the manifest file are ignored.

    If you want to run a script on a tab from your extension, use chrome.extension.getViews in your background script. Even better, design your extension's pages such that they effectively communicate with each other (example).

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