Book Image

NW.js Essentials

Book Image

NW.js Essentials

Overview of this book

Table of Contents (17 chapters)
NW.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

The DevTools API


The DevTools API is a part of the Window APIs seen in Chapter 2, NW.js Native UI APIS, and it provides three methods:

  • Window.isDevToolsOpen()

  • Window.closeDevTools()

  • Window.showDevTools([id | iframe, headless])

The first two methods are pretty much self-explanatory, while the third one deserves to be dived deep into.

The most common use of Window.showDevTools is without parameters. This way, you can open DevTools at runtime without having to enable the window toolbar:

require('nw.gui').Window.get().showDevTools();

The first parameter [id|iframe] allows us to set the target frame for which debugging is to be enabled. Let's see an example:

<iframe src= "test.html" id="toDebug" ></iframe>
<script type="text/javascript">
var win = require('nw.gui').Window.get();
win.showDevTools('toDebug');
</script>

This way, DevTools will be enabled only on the #toDebug iframe. Its value can be set to the ID or the object of the iframe element.

The second parameter, headless,...