Add window management to your Nightmare scripts.
Simply require the library:
var Nightmare = require('nightmare')
require('nightmare-window-manager')(Nightmare)
... and then enable the window manager with .windowManager()
. It should be the first call in your Nightmare chain.
Sets up window management.
Gets a listing of the windows currently open under the Nightmare instance.
Waits for all of the windows to no longer be in a loading state.
Gets the current window.
Closes the window specified by the window ID. If the current window is the one being closed, the first non-closed window is set as focused. WARNING: do not close the ID 1 as that will dispose the Nightmare plumbing.
Sets the given window ID as focused.
Invokes fn
on the currently selected window with the arguments supplied. All of the arguments are optional. On completion, it returns the return value of fn
, same as Nightmare's .evaluate()
.
var Nightmare = require('nightmare');
require('nightmare-window-manager')(Nightmare);
var nightmare = Nightmare();
nightmare
.windowManager()
.goto(url)
.click('#something_opens_a_window')
.waitWindowLoad()
.currentWindow()
.then(function(window){
//window contains useful information about the newly-opened window,
//including the window ID
console.dir(window)
});