Book Image

NW.js Essentials

By : Alessandro Benoit, Roger Weng
Book Image

NW.js Essentials

By: Alessandro Benoit, Roger Weng

Overview of this book

Table of Contents (17 chapters)
NW.js Essentials
About the Author
About the Reviewers

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:


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();

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,...