Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to end nightmare #835

Closed
neutron92 opened this issue Oct 17, 2016 · 10 comments
Closed

how to end nightmare #835

neutron92 opened this issue Oct 17, 2016 · 10 comments

Comments

@neutron92
Copy link

neutron92 commented Oct 17, 2016

Please how to end nightmare by separeted button i want to do a start and stop button
PS:

Nightmare({
        show: false,
        openDevTools: false
    });
@rosshinkley
Copy link
Contributor

I'm not entirely sure I understand the question. Nightmare can be ended with .end(), and in the future interrupted with .halt() (see #788).

The "button" part of your question confuses me: what are you trying to do?

@neutron92
Copy link
Author

neutron92 commented Oct 19, 2016

@rosshinkley i want to stop the nightmare by a button
i want to do a button that start my script contains nightmare then when i want to stop the nightmare with an other button because in the server i can't see the electron to stop it
did u undertand me now?

@rosshinkley
Copy link
Contributor

Yes. I think in that case you'd want the .halt() API, which is as-yet not included.

@neutron92
Copy link
Author

i got u ok thanks a lot for ur answer

@shtefcs
Copy link

shtefcs commented Oct 19, 2016

@rosshinkley do you know maybe when .halt() API will be included ?

We need it for project of ours.

If that will not be soon, do you suggest any solutions ?

Peace!

@entrptaher
Copy link
Contributor

I don't know about the halt() function but basically I did another workaround.

Creating a nightmare window without calling end()
Then add a button to call only the end()

Maybe you wanted a pause button too. But I suppose this one was the best thing I could come of with.
Here is something else to help you understand my perspective.

First I do this to run nightmare inside electron,
#856 (comment)

Then I use this index.html file.

<button id="start">Start</button>
<button id="stop">Stop</button>
<b id="status">idle</b>
<b id="results"></b>

<script>
// We allow nightmare to wander in the global scope by defining it here, 
// otherwise we would not be able to call it multiple times
var Nightmare = require('nightmare');
var nightmare;
var args = { show: true, alwaysOnTop: false };


document.getElementById("start").addEventListener("click", function(){
  document.getElementById("status").innerHTML = "Searching for the gem";

  // Here we start the Nightmare Instance
  nightmare = Nightmare(args);
  nightmare
    .goto('http://yahoo.com')
    .type('form[action*="/search"] [name=p]', 'github nightmare')
    .click('form[action*="/search"] [type=submit]')
    .wait('#main')
    .evaluate(function () {
      return document.querySelector('#main .searchCenterMiddle li a').href
    })
    .then(function (result) {
      document.getElementById("results").innerHTML = result;
    })
    .catch(function (error) {
      document.getElementById("results"). innerHtml = "Search failed: " + error;
    });

})
document.getElementById("stop").addEventListener("click", function(){
  nightmare
  .end()
  .then(function (result) {
      document.getElementById("status").innerHTML = "Leaving Nightmare Speechless";
    })
})
</script>

And the result is this,

It might look really stupid, but this works for me I guess.

@shtefcs
Copy link

shtefcs commented Oct 29, 2016

@entrptaher Wow, tnx a lot for trying to help mate, really appreciate!

I will need to wait someone to do this for me, cause current guy who was doing this left the work.

@entrptaher how can I get in contact with you ? My email is stefan@vanila.io, so you can reach me there or join our internal chat on https://chat.vanila.io

@jelenajjo
Copy link

Thank you @entrptaher

@entrptaher
Copy link
Contributor

Glad to be of help.

@Raidus
Copy link

Raidus commented Jul 7, 2017

Thanks @entrptaher for your example!

I've tried to rebuild your example, but nightmare isn't starting in my case.

Could have a look at https://github.com/Raidus/test-electron-nightmare?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants