I ran into this problem. You think there will be an obvious solution. Here is what I did for firefox (didn't work with chrome):
I have a lib / dbg.js file containing my main debugging features that I want to use everywhere.
In every module supporting content in my main.js, I have the following:
contextMenu.Item({ ... contentScript: export_internals(require('dbg')), contentScriptFile: my-actual-scripts.js ...
and then basically I have a function
function export_internals(module) { var code = ''; for (name in module) { var val = module[name]; if (val.constructor === String) code += name + ' = "' + val + '";'; else code += val; } return code; }
which basically just cycles through the exported properties (variables, functions, etc.) and uses things like Function.toString () to basically build a gated version of the dbg module and pass it as inline content script. This function is probably not extremely general, as I just wrote it to handle simple functions and strings (only for the two data types that I need), but the principle should be easily applied, even if you just do something like
contentScript: require('dbg').my_function.toString()
This is clearly a bit hacky, but pretty reliable. Is this what you were looking for?
Evan donahue
source share