the code:
var Nightmare = require('nightmare');
var nightmare = Nightmare({show:true});
nightmare
.goto('https://duckduckgo.com')
.evaluate(() => { return document.title; })
.end()
.then((title) => {
console.log(title);
nightmare.pdf(title, {printBackground: true});
});
Why it isn't saving the pdf with "title"? And even if I change the title to some string like pdf.pdf
it still doesn't work inside .then()
why is that?
I have found out why it was happening:
The .end()
was causing the other functions not to work inside .then
, after moving it inside .then
it started working as needed. Code:
nightmare
.goto('https://duckduckgo.com')
.evaluate(() => { return document.title; })
//.end() // <= this one is bad
.then(function (title) {
console.log(title);
nightmare.end() // <= This one is good.
return nightmare.pdf(title, {printBackground: true});
})