For my web extension I would like to have a "debug mode" which makes troubleshooting issues with the extension easier. By default this debug mode should be disabled, but it should be possible to enable it at runtime.
I don't have a settings page for the extension yet (and am also not planning on adding one soon), so I don't want to create one just for enabling this debug mode. Also the debug mode should hopefully rarely be needed.
Therefore one approach I was thinking of is using the Console of the background script when debugging the extension in the browser (Firefox, Chrome), to somehow inform the background script or modify its state to enable the "debug mode" of my extension.
For Firefox and Chrome what seems to work is:
- In the debug Console set a custom
windowproperty / global variable, for examplemyExtDebug = true - In the background script check
window.myExtDebug === true
However, my questions are:
- Are there any downsides of this
windowapproach, for example security-wise? How reliable is it / to what extent does it rely on implementation details?
(Note that I am using a property name which includes the name of my extension, so chances of an accidental collision with another property should be low.) - What other approaches exist?
windowapproach works for Chrome as well. Must have done something wrong during initial testing. Have updated the question now.