# Alltogether: opening a JavaScript debugger within Oxygen [JS Operations](https://www.oxygenxml.com/doc/versions/23.1/ug-editor/topics/dg-default-author-operations.html#dg-default-author-operations__jsoperation) through inclusion This rambling shows how a [debugger](../js-debugger) can be launched using an [inclusion](../js-include). ## Installation To do so: ### 1) add the include() function to your commons.js file: ```javascript include = function (filepath, isAbsolute) { if (isAbsolute === undefined || isAbsolute == false) { filepath = Packages.ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil.expandAndResolvePath(authorAccess, filepath); } var text = new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths. get (java.net.URI(filepath)))); text = String(text); eval(text); } ``` ### 2) create a debugger.js file: ```javascript startDebugger = function () { var runnable = { run: function () { main.dispose(); } } var context = Packages.org.mozilla.javascript.Context.getCurrentContext(); // Within the current context... var contextFactory = context.getFactory(); var scope = Packages.org.mozilla.javascript.tools.shell.Environment(runnable.__parent__); // and the scope of the runnable variable's parent ... var main = Packages.org.mozilla.javascript.tools. debugger.Main.mainEmbedded(contextFactory, scope, 'Debugger'); // start a debugging session ... main.setExitAction(java.lang.Runnable(runnable)); // , clean the resources at exit time... main.setVisible(true); // and make it visible/ } ``` ### 3) Use these functions in your doOperation() method: ```javascript doOperation = function () { include('debugger.js'); startDebugger(); } ``` ## See also More details on these hacks: * [debugger](../js-debugger) * [inclusion](../js-include) # Framework This directory includes the Oxygen sample framework on which ou can test these techniques but they should work on any framework.