I'm trying to insert HTML into the body of a web page using NightmareJS. I'm using the following code to work within the document scope:
await nightmare.evaluate(function(users) {
for(var i = 0; i < users.length; i++) {
var matchResult = users[i].match(/.com\/(.*?)\?fref/);
if (matchResult) {
document.body.innerHTML += '<a href="https://www.example.com/'+matchResult[0]+'">'+matchResult[0]+'</a>';
}
}
}, users);
console.log("we got here");
The console.log
never happens. Instead I get:
Error: Evaluation timed out after 30000msec. Are you calling done() or resolving your promises?
at Timeout._onTimeout (/home/user/www/project/bin/scraper/node_modules/nightmare/lib/actions.js:509:10)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
If I remove the innerHTML
line, it executes fine and I can return values from matchResult
. What's wrong here?
Edit: Here are related issues:
https://github.com/segmentio/nightmare/issues/759
https://github.com/segmentio/nightmare/issues/688#issuecomment-238473332