Nightmare.js 不适用于 Azure 网络作业

Nightmare.js does not work with Azure webjob

我正在尝试 运行 一个 azure webjob,它接受一个 json 对象并呈现一个网页,然后通过 Nightmare.js 中的电子浏览器将其打印为 pdf。

当我 运行 在本地运行时它完美运行,但是当我 运行 在 azure webjob 中它永远不会完成。
我将两个 console.log 语句输出到日志,但是看到我无法从 nightmare.js 调用中输出任何内容,也无法显示电子浏览器 window,我不知道发生了什么错了。

脚本中还有一个网络服务器,省略了,因为它似乎接受带有 json 对象的请求并将其传递给 createPage 就好了。

我已验证 index.html 文件位于正确的目录中。有谁知道可能出了什么问题?

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);
    });
}

已解决

正如里克在他的回答中所说,这目前行不通! 本文档列出了 webjobs 沙箱的当前状态:
https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox
它有以下与我的问题相关的段落:

PDF generation from HTML

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.

我想 nightmare.js 需要桌面交互才能正常工作,而 WebJob 无法做到这一点。

摘自 this issue 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).

这不会在 Azure WebJob 上运行。