Nightmare.js不适用于Azure Webjob [英] Nightmare.js does not work with Azure webjob

查看:89
本文介绍了Nightmare.js不适用于Azure Webjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个Azure Web作业,该作业需要一个json对象并呈现一个网页,然后通过Nightmare.js中的电子浏览器将其打印为pdf.

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.

当我在本地运行它时,它可以完美运行,但是当我在天蓝色的webjob中运行它时,它永远不会完成.
我将两个console.log语句输出到日志,但是看到我无法从nightmare.js调用中输出任何内容,也无法显示电子浏览器窗口,所以我不知道出了什么问题.

When I run this locally it works perfectly, but when I run it in azure webjob it never completes.
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.

该脚本中还有一个Web服务器,由于似乎可以将请求与json对象一起使用并将其传递到createPage就可以了,因此省略了.

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.

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

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

已解决

正如里克(Rick)在他的回答中指出的那样,这目前不起作用! 该文档列出了webjobs沙箱的当前状态:
https://github.com/projectkudu/kudu/wiki/Azure- Web应用程序沙箱
它具有与我的问题有关的以下段落:

Solved

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

从HTML生成PDF

有多个库可用于将HTML转换为PDF.许多Windows/.NET特定版本使用IE API,因此广泛使用User32/GDI32.这些API在沙盒中大部分被阻止(无论计划如何),因此这些框架在沙盒中不起作用.

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.

有些框架没有充分利用User32/GDI32(例如wkhtmltopdf),我们正在以与启用SQL报表相同的方式在Basic +中启用这些框架.

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.

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

来自Github上的此问题:

Taken from this issue on Github:

噩梦并不是真的没有头脑:它需要一个Electron实例才能 工作,而这又需要一个帧缓冲区来正确渲染(在 至少现在).

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上显示.

This will not fly on an Azure WebJob.

这篇关于Nightmare.js不适用于Azure Webjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆