4

Google Chrome themes are defined on the Chrome developer docs as follows:

A theme is a special kind of extension that changes the way the browser looks. Themes are packaged like regular extensions, but they don't contain JavaScript or HTML code.

(emphasis my own)

However I would like to apply some kind of theme which does run JavaScript on the page I load. How can I do this? I have tried adding

"permissions": ["<all_urls>"],
"content_scripts": [
    {
    "matches": [
        "http://*/*",
        "https://*/*"
        ],
    "js": ["content.js"],
    "run_at": "document_end"         // pay attention to this line
    }
],

to my manifest.json and putting the content.js file below in the same .crx package as my manifest as per this answer

(function(window, chrome){
  "use strict";
  var doc = window.document;
  doc.getElementById("mv-tiles").style.opacity = "0";
}(window, chrome));

but the code just doesn't run. Are there any workarounds?

Pacerier
  • 86,231
  • 106
  • 366
  • 634
Greedo
  • 4,967
  • 2
  • 30
  • 78
  • 1
    So, the docs state unequivocally that you can't, and you're asking us how to do it? – ceejayoz Aug 12 '17 at 00:21
  • @ceejayoz Not asking how to run code from the file, I'm asking for a good workaround which achieves the same goal. I asked this a while ago and have since used TamperMonkey to run the script (although I hear the ability to run scripts on the New Tab page is being phased out anyway) - but I didn't think it was a very *good* workaround as it involves installing additional software, and I want my themes to be portable and self contained if I can. – Greedo Aug 12 '17 at 08:45
  • 1
    just in case this question is still relevant, you can see that most startup themes are rly not themes, but extensions, so you would have to develop and extension. – 404answernotfound Aug 29 '18 at 14:49

1 Answers1

1

As others have correctly said in the comments, this is not possible with a theme and has to be published as an extension instead.

There is a security issue to take into consideration here: Because themes cannot contain "active" JavaScript code they are inherently more secure than extensions. This plays a role in larger companies which apply security policies on browsers. They may allow installation of themes as they only contain static content, but refuse installation of extensions.

This security feature must be enforced by the browsers or it will no longer make any sense and the difference between themes and extensions becomes irrelevant.

exhuma
  • 20,071
  • 12
  • 90
  • 123