I'm having a hell of a time getting this to run on Travis CI. It works intermittently, but more often than not nightmare fails with this error:
nightmare:log did-get-response-details [{},false,"https://fonts.gstatic.com/s/roboto/v16/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2","https://fonts.gstatic.com/s/roboto/v16/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2",200,"GET","https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons",{"accept-ranges":["bytes"],"access-control-allow-origin":["*"],"age":["706260"],"alt-svc":["quic=\":443\"; ma=2592000; v=\"37,36,35\""],"cache-control":["public, max-age=31536000"],"content-length":["14696"],"content-type":["font/woff2"],"date":["Mon, 17 Apr 2017 21:24:49 GMT"],"expires":["Tue, 17 Apr 2018 21:24:49 GMT"],"last-modified":["Tue, 04 Apr 2017 18:34:45 GMT"],"server":["sffe"],"status":["200"],"timing-allow-origin":["*"],"x-content-type-options":["nosniff"],"x-xss-protection":["1; mode=block"]},"other"] +0ms
nightmare:log did-stop-loading [{}] +276ms
nightmare:log crashed [{},false] +1ms
nightmare:actions .wait() for .main-container element or 1000msec +29s
nightmare:actions .evaluate() fn on the page +1s
/home/travis/build/esalter-va/esalter-va.github.io/node_modules/webpack-static-site-generator/render.js:30
setTimeout(function () {throw err})
^
Error: Evaluation timed out after 30000msec. Are you calling done() or resolving your promises?
at Timeout._onTimeout (/home/travis/build/esalter-va/esalter-va.github.io/node_modules/nightmare/lib/actions.js:509:10)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
I am trying to run a Webpack extension that uses Nightmare. The code is here, but the just of my setup is as follows.
// plugin: index.js
if (process.platform === 'linux'){
xvfb.startSync()
process.env['DISPLAY'] = ':99.0'
}
var server = serve(self.outputPath)
var port = server.address().port
var outputFiles = render(port, self.routes, self.elementToWaitFor)
outputFiles.then(files => {
for (var i = 0; i < files.length; i++) {
var outputFilePath = path.join(self.outputPath, self.routes[i])
var outputFileName = path.join(outputFilePath, 'index.html')
fsPath.writeFile(outputFileName, files[i])
}
server.close(function () {
xvfb.stopSync()
done()
})
}).catch(err => {
setTimeout(function () {throw err})
server.close(function () {
xvfb.stopSync()
done()
})
})
// plugin: render.js (where `var outputFiles = render(port, self.routes, self.elementToWaitFor)` goes)
function render(port, routes, elementToWaitFor) {
var nightmare = Nightmare({
show: false,
webPreferences: {
partition: 'partition-' + Math.random()
}
})
var baseUrl = `http://localhost:${port}`
var pageContents = routes.reduce(function (accumulator, route) {
return accumulator.then(function (results) {
var url = baseUrl + route
return nightmare
.goto(url)
.wait(elementToWaitFor, 1000)
.evaluate(function () {
return document.documentElement.innerHTML
})
.then(function (content) {
results.push(content)
return results
})
.catch(err => {
setTimeout(function () {throw err})
})
})
}, Promise.resolve([]))
return pageContents.then(function (values) {
return nightmare.end().then(function () {
return values
})
}).catch(err => {
setTimeout(function () {console.log(`Error ${err}`)})
})
}
# .travis.yml (project that uses plugin)
language: node_js
node_js:
- "node"
addons:
apt:
packages:
- xvfb
- libxss1
script:
- yarn run lint
- yarn run build
// package.json
"scripts": {
"build": "DEBUG=nightmare:*,electron:* node build/build.js",
},
The build script runs Webpack, which runs my Nightmare script. Here's a Gist with the full error log.
I've tried every solution I can find online, and nothing seems to be working.
Some of the things I've tried (that I can remember:
Nightmare({show: false})
Nightmare({webPreferences: {partition: 'partition-' + Math.random()}
.wait()
apt
packages as different posts online suggestedAny help would be greatly appreciated, and if I missed anything, please let me know!
This seems to have been resolved by adding sudo: required
to my .travis.yml
.