javascriptgoogle-chromegoogle-chrome-extensionchrome-options

Chrome extension options


In the manifest.json of my extension, I added this:

  "options_ui": {
      "page": "options.html",
      "chrome_style": true
  },

My options page (options.html) has this right before the closing body tag:

<script src="options.js"></script>

Both options.html and options.js are in the same folder. options.js starts with this:

console.log('options.js');

Problem: I am loading the unpacked extension (developer mode enabled). My options page is showing fine, but the script is not loaded. I have defined event handlers in that file, and they do nothing. options.js is not executed.

I followed all the instructions here, but it just does not work.


Solution

  • the new "chrome_style" options actually don't show anything logged to the console trough console.log, your script is probably fine, try adding something to the dom.

    Add this at the beginning of your script to see any errors happening in your chrome options page:

    var errorText = document.createElement("div");
    document.body.appendChild(errorText)
    window.onerror = function (msg, file, line, column) {
      errorText.innerHTML = msg + '<br>' + file + ' ' + line + ':' + column;
    }
    

    EDIT: Right click inside the Options UI, select "Inspect element", it will open the appropriate debugger.