Copied from my post on StackOverflow (
http://stackoverflow.com/q/33808596/1814970).
I have the following code, in a new extension I am working on:
(.addListener js/chrome.alarms.onAlarm (fn [alarm] (.log js/console alarm)))
(.addListener js/chrome.commands.onCommand (fn [command] (.log js/console command)))
(.addListener js/chrome.browserAction.onClicked (fn [] (.log js/console "clicked!")))
My :cljsbuild looks like this:
{:id "background"
:source-paths ["src/folder/background"]
:compiler {:output-dir "resources/public/js/compiled/background"
:output-to "resources/public/js/compiled/background/background.js"
:main folder.background.background
:optimizations :advanced
:pretty-print true
:source-map "resources/public/js/compiled/background/background.js.map"
:externs ["resources/public/js/chrome_extensions.js"]}}
The code is exactly in the order shown. The bizarre thing is that the first and third lines work, while the second does nothing. My manifest.json (relevant parts) looks like this (there is no parsing error):
"background": {
"scripts": [
"path/to/compiled/file.js"
]
},
"permissions": [
"alarms",
"commands"
],
"commands": {
"do-something": {
"suggested_key": {
"default": "Alt+Shift+D"
},
"description": "Do it!"
}
}
I have advanced compilation on and I have the correct extern file (this works, except for this particular case).
Last, but not least, I did a JavaScript version of this and the same thing works. How can it be??
chrome.commands.onCommand.addListener(function (command) {
console.log(command);
});
Thanks in advance!