Nightmare.js does not work with Azure webjob


I am trying to run an azure webjob which takes a json object and renders a webpage, then prints it to pdf, via the electron browser in Nightmare.js.

When I run this locally it works perfectly, but when I run it in azure webjob it never completes.<br /> I get the two console.log statements output to the log, but seeing as I can not output anything from the nightmare.js calls, nor display the electron browser window, I have no idea what is going wrong.

There is also a webserver in the script, omitted as it seems to take the request with the json object and pass it to createPage just fine.

I have verified that index.html file is in the right directory. Does anyone know what might be wrong?

var Nightmare = require('nightmare'), http = require('http'); function createPage(o, final) { var start = new Date().getTime(); var page = Nightmare({ //show: true, //uncomment to show electron browser window //openDevTools: { mode: 'detach'}, //uncomment to open developer console ('show: true' needs to be set) gotoTimeout: 300000, //set timeout for .goto() to 2 minutes waitTimeout: 300000, //set timeout for .wait() to 5 minutes executionTimeout: 600000 //set timeout for .evaluate() to 10 minutes }) .goto('file:\\\\' + __dirname + '\\index.html'); page.wait("#ext-quicktips-tip") //wait till HTML is loaded .wait(function () { // wait till JS is loaded console.log('Extjs loaded.'); return !!(Ext.isReady && window.App && App.app); }); console.log("CreatePage()1"); page.evaluate(function (template, form, lists, printOptions) { App.pdf.Builder.create({ template: template, form: form, lists: lists, format: o.printOptions.format, }); console.log('Create done'); }, template, form, o.lists, printOptions); console.log("CreatePage()2"); page.wait(function () { console.log('Content created. ' + App.pdf.Builder.ready); return App.pdf.Builder.ready; }) .pdf(o.outputDir + form.filename, { "pageSize": "A4", "marginsType": 1 }) .end() .then(function () { console.log('Pdf printed, time: ' + (new Date().getTime() - start) / 1000 + ' seconds'); final(true); }) .catch(function (err) { console.log('Print Error: ' + err.message); }); }


As Rick states in his answer, this will not currently work! This document lists the current state of webjobs sandbox:<br /><a href="https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox" rel="nofollow">https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox</a><br /> It has the following paragraph relating to my issue:


<strong>PDF generation from HTML</strong>

There are multiple libraries used to convert HTML to PDF. Many Windows/.NET specific versions leverage IE APIs and therefore leverage User32/GDI32 extensively. These APIs are largely blocked in the sandbox (regardless of plan) and therefore these frameworks do not work in the sandbox.

There are some frameworks that do not leverage User32/GDI32 extensively (wkhtmltopdf, for example) and we are working on enabling these in Basic+ the same way we enabled SQL Reporting.



I guess for nightmare.js to work you need desktop interaction, which you're not getting on a WebJob.

Taken from <a href="https://github.com/segmentio/nightmare/issues/744" rel="nofollow">this issue</a> on Github:


Nightmare isn't truly headless: it requires an Electron instance to work, which in turn requires a framebuffer to render properly (at least, for now).


This will not fly on an Azure WebJob.


  • Java and Ruby: “everything is an object” in OO?
  • how to get the content fragment at onTabChanged(String tabTag)
  • Can I manage incomplete class objects using STL containers?
  • Why are the key words abstract and void in a php Interface?
  • SQLite database partitioning
  • How can I programmatically shutdown a node program and restart it?
  • Setting Unknown Array Boundaries and Loop
  • Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css
  • How do I get HTML corresponding to current DOM tree?
  • print() is showing quotation marks in results
  • Swift: Switch statement fallthrough behavior
  • Asynchronous UI Testing in Xcode With Swift
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Why is an OPTIONS request sent to the server?
  • How can I send an e-mail from a vbs script
  • Illegal mix of collations for operation for date/time comparison
  • Spring security and special characters
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • How do I fake an specific browser client when using Java's Net library?
  • Date difference with leap year
  • angularjs unit test when to use $rootScope.$new()
  • Volusion's generic SQL folder, functionality
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Menu Color Fade on Hover with Jquery
  • Can I make an Android app that runs a web view in Chrome 39?
  • How to show dropdown in excel using jrxml (jasper api)?
  • How to limit post in wp_query
  • Hazelcast - OperationTimeoutException
  • How to make Safari send if-modified-since header?
  • Adding custom controls to a full screen movie
  • File upload with ng-file-upload throwing error
  • A cron job substitute?
  • How to set the response of a form post action to a iframe source?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • reshape alternating columns in less time and using less memory