Could I make a Google Chrome extension for chrome pages (downloads, extensions etc)?

后端 未结 3 1561
难免孤独
难免孤独 2020-12-19 20:29

I\'d like to make a very simple extensions that slightly alters how the Downloads page looks. Changing the History page might be interesting too, but that\'s for later.

相关标签:
3条回答
  • 2020-12-19 21:13

    According to this documentation, chrome:// URLs are an invalid scheme so they won't be matched:

    A match pattern is essentially a URL that begins with a permitted scheme (http, https, file, or ftp), and that can contain '*' characters.

    I would look into using override pages instead.


    As requested, here's my extension that can at least load when chrome://downloads is loaded, although as I said, I don't think you can modify the page even if you know that's the page you're viewing.

    manifest.json

    {
        "name": "Test",
        "version": "0.0.1",
        "background_page": "background.html",
        "permissions": [
            "tabs"
        ]
    }
    

    background.html

    <script>
        chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
        {
            if (tab.status == "complete")
            {
                alert(tab.url);
                // should alert 'chrome://downloads' on that page. You can 
                // check for this url here and then do whatever you want
            }
        });
    </script>
    
    0 讨论(0)
  • 2020-12-19 21:13

    Update: Since Chrome 31 there is an API for extensions that allows access to Chrome's downloads: https://developer.chrome.com/extensions/downloads

    There's also an API that allows access to list and manage other installed extensions: https://developer.chrome.com/extensions/management


    (Previous Answer)

    Unfortunately, there's not currently an API for Chrome extensions to access information about a user's downloads. It's a widely requested feature, though, and there's some discussion among Chrome developers here: http://code.google.com/p/chromium/issues/detail?id=12133

    Star the issue if it's a feature that you'd like to see, and you'll receive email updates.

    0 讨论(0)
  • 2020-12-19 21:14

    As this page shows, there is no API to override the downloads page... However, there is a way to make a file you have made replace the chrome://downloads/ page whenever it is loaded using javascript in your background page...

    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
      if(changeInfo.status === "loading"){
        if(tab.url === "chrome://downloads/"){
          chrome.tabs.update(tab.id, {url: "REPLACEMENT.html"});
        } 
      }
    });
    

    Essentially what this does is - As soon as the page chrome://downloads begins loading (using the tabs.onUpdated API), the page is redirected to REPLACEMENT.html (Using tabs.update API)... There is no visible delay in the tab update as this script is run before the chrome://downloads page begins loading... You can use a similar code in your file by pressing CTRL + U on the downloads page to view and copy its source code

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