WebExtensions - javascript support in browser_action/default_popup page

On Chrome, clicking on a link in the default_popup window closes it.

This is not the case in the current Firefox Nightly, so I wanted to do it with a call to window.close() on the onclick event handler but it seems that the popup window doesn’t behave as the other html pages regarding javascript support : alert() works but neither window.close() nor console.log().
There is no error message in the console.

manifest.json:

{
  "manifest_version": 2,
  "name": "webextensions tests",
  "version": "1.0",

  "applications": {
    "gecko": {
      "id": "webextensions@bourcereau.fr"
    }
  },

  "browser_action": {
        "default_title": "Tests",
        "default_popup": "popup.html"
    }
}

popup.html:

<!doctype html>
<html>
<body>
  <a href="#" onclick="alert('something')">alert : ok</a><br>
  <a href="#" onclick="console.log('something')">console.log : not ok</a><br>
  <a href="#" onclick="window.close()">window.close : not ok</a><br>
</body>
</html>

Complete extension source here : https://github.com/mmai/firefox_webextensions_tests

1 Like

I found that you can see the console.log() output using Ctrl-Shift-J. It helps with some debugging, though still it looks very limited.

1 Like

Thank you. At least now I can see the error message : “Scripts may not close windows that were not opened by script”. Now I wonder how we are supposed to close this popup window…

You can see all info in this ctrl-shift-j log, you just have to enable the pereferences to see it all: https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment?redirectlocale=en-US&redirectslug=Setting_up_extension_development_environment#Development_preferences

1 Like

These developer perfences should be the first (and only really) thing you need to do before starting to dev. It shouldn’t be hard to find. I linked to it from the main addons landing page “debugging” section: https://developer.mozilla.org/en-US/Add-ons