2021-04-25 12:37:47 +00:00
# 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
2021-04-25 08:49:16 +00:00
2021-04-25 12:37:47 +00:00
This rambling shows how a [debugger ](../js-debugger ) can be launched using an [inclusion ](../js-include ).
2021-04-25 08:49:16 +00:00
## Installation
2021-04-25 12:37:47 +00:00
To do so:
### 1) add the include() function to your commons.js file:
2021-04-25 08:49:16 +00:00
```javascript
2021-04-25 12:37:47 +00:00
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);
2021-04-25 08:49:16 +00:00
}
```
2021-04-25 12:37:47 +00:00
### 2) create a debugger.js file:
2021-04-25 08:49:16 +00:00
```javascript
2021-04-25 12:37:47 +00:00
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/
}
2021-04-25 08:49:16 +00:00
```
2021-04-25 12:37:47 +00:00
### 3) Use these functions in your doOperation() method:
2021-04-25 08:49:16 +00:00
```javascript
2021-04-25 12:37:47 +00:00
doOperation = function () {
include('debugger.js');
startDebugger();
2021-04-25 08:49:16 +00:00
}
```
2021-04-25 12:37:47 +00:00
## See also
More details on these hacks:
* [debugger ](../js-debugger )
* [inclusion ](../js-include )
2021-04-25 08:49:16 +00:00
# Framework
2021-04-25 12:37:47 +00:00
This directory includes the Oxygen sample framework on which ou can test these techniques but they should work on any framework.
2021-04-25 08:49:16 +00:00