Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

Is there a way to do that?

I tried making a Content Script extension, with "chrome://downloads" as match in manifest.json. Chrome won't allow that and responds with an error when packaging the extension.

Is there another simple way? It has to be simple, because changes would be simple, because all chrome:// pages are built with HTML, JS and CSS.

edit
After trying with background scripts a little...

I can't get chrome.tabs.executeScript to work! I added in background.html:

chrome.browserAction.onClicked.addListener(function(tab) {
    alert(this.document.body.innerHTML);
    alert(chrome.tabs.executeScript(null, {
        code : "document.body.style.backgroundColor = 'red';"
    }));
});

And I added this in manifest.json to add a (invisible) 'browser action button':

    ,"browser_action": {
/*      "popup": "background.html",*/
        "name": "Alter page"
    }

The onClicked event fires both alerts (first is background.html's body, second is undefined). But the code (a string with document.body.style.backgroundColor = 'red';) doesn't execute! And ofcourse there's no debugging for extensions like this =)

Any tips anyone? I'm trying to get a hold of the tab's window.document (not background.html's window.document!). An injected script (that's what chrome.tabs.executeScript is supposed to do) should do that.

PS
I'm stealing from make_page_red/manifest and make_page_red/background.html
The 'extension' I have so far: http://hotblocks.nl/js/downloads.rar

EDIT
I found out what I want to achieve is possible with just CSS. I don't need to inject javascript. Does that make it easier? Does that make it possible? =)

like image 365
Rudie Avatar asked Sep 08 '25 01:09

Rudie


1 Answers

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>
like image 148
Jimmy Sawczuk Avatar answered Sep 11 '25 19:09

Jimmy Sawczuk