segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.55k stars 1.08k forks source link

Nightmare program with Electron in Production Environment(IIS) is not working. There is no response from the nightmare.goto(url) call. #1478

Open jubishkammily opened 6 years ago

jubishkammily commented 6 years ago

Hello ,

I have created an application wit NightmareJs with Electron to get the screen shot of a rendered image. This application is working in the development environment but after deploying it in the production environment its not giving me any responses.

I am not able get any error messages also back from the nightmare.goto(url) call. I am not able to resolve this since there is no error message from the module.

How to get error messages back in production environemnt ?

A simpe nightmare program is not giving any response at all.


 var nightmare = new Nightmare({
        frame: false,
        show: false
    });

nightmare.goto(url)
    .evaluate(chartDefenitionJsonObj => {

        c3.generate(chartDefenitionJsonObj);
    }, chartDefenitionJsonObj);

    var outputFilePath = "./graph.png";
    nightmare.wait(selector)
        .evaluate(() => {
            const body = document.querySelector('body');
            const element = document.querySelector('svg');
            const rect = element.getBoundingClientRect();
            return {
                bodyWidth: body.scrollWidth, // Get dimensions of the page.
                bodyHeight: body.scrollHeight,
                x: rect.left,
                y: rect.top,
                height: rect.bottom - rect.top,
                width: rect.right - rect.left
            };
        })
        .then(rect => {
            .screenshot(outputFilePath);
        })
        .then((buffer) => {
           callback("", buffer);
            return nightmare.end();

        })
        .catch(err => {

            callback(err, "")
            return nightmare.end();

        });
jubishkammily commented 6 years ago

Anybody here who can help me on this ?

srgraham commented 6 years ago

I'm getting similar issues. I think it's because my production is a headless server. (That's the only thing I can think of that's different)

No .then() gets hit, no .catch() gets hit. Running everything in a try/catch doesn't catch anything. All that happens is the code exits (without error), since the event loop detects there's nothing to run. I'm still attempting to debug this.

srgraham commented 6 years ago

This solved it for me on linux environment: https://www.linode.com/docs/development/nodejs/use-nightmarejs-to-automate-headless-browsing/#create-and-run-the-automation-script