segment-boneyard / nightmare

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

Reference error evaluating document #1425

Open JereMc opened 6 years ago

JereMc commented 6 years ago

I tried the call this way:

let nightmare = Nightmare({ show: false});
  (async () => {
    try {
      const doc = await nightmare
        .goto(url)
        .evaluate(() => {
          return document.documentElement.innerHTML;
        })
        .end();
      return doc;
    } catch(e) {
      console.error(e);
      return undefined;
    }
  })();

and this way:

let nightmare = Nightmare({ show: false});
  nightmare
    .goto(url)
    .evaluate(() => {
      return document.documentElement.innerHTML;
    })
    .end()
    .then(doc => {
      return doc;
    })
    .catch(function(err) {
      console.log(err);
      return null;
    });

and with both I get:

{ ReferenceError: cov_eneajp1f5 is not defined at fn (:6:5) at javascript (:24:21) at :39:3 at EventEmitter.electron.ipcRenderer.on (/Users/jeremiahmcallister/Developer/Desirelist/desirelist-api/application/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js:63:28) at emitMany (events.js:146:13) at EventEmitter.emit (events.js:223:7) code: -1 }

When I create a test file with the above code and run it using node test.js it works. But, when I try to call it from a node api it doesn't. It seems like it doesn't recognize document.

I say that because when I run an example like this

nightmare.goto('http://example.com')
    .title()
    .then(function(title){
        console.log(title);
    });

from the api it works fine.

Any ideas why?

eddiewang commented 4 years ago

@JereMc did you ever manage to figure out the root cause of this issue?