Reuse Electron Session With Nightmare
I am using Nightmare.js to print pdf's. I send a request to the node server and build the page, using Nightmare to ensure the page has loaded, then print a pdf. But for each reque
Solution 1:
You need to create the nightmare instance once and not in a loop.
var page = nightmare()
.goto('file:\\\\' + __dirname + '\\index.html');
This creates new nightmare instance each time you create a page. You can create instance once
constNightmare = require('nightmare');
const browser = Nightmare();
Then use it each time with browser.goto(url). You can chain your goto statment using answers given at: https://github.com/segmentio/nightmare/issues/708
Extract from one of the answers:
functionrun() {
var nightmare = Nightmare();
yield nightmare
.goto('https://www.example.com/signin')
.type('#login', 'username')
.type('#password', 'password')
.click('#btn')
for (var i = 0; i < 4; i++) {
yield nightmare
.goto('https://www.example.com/page'+i)
.wait(1000)
.evaluate(function(){
return $('#result > h3').text()
})
}
yield nightmare.end()
}
You can also create multiple browsers, for pooling as well.
var browser1 = Nightmare();
var browser2 = Nightmare();
Post a Comment for "Reuse Electron Session With Nightmare"