tel2 has asked for the wisdom of the Perl Monks concerning the following question:

Beloved Monks,

I've just run the this, code, i.e.:

use WWW::Mechanize::PhantomJS; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('http://google.com'); $mech->eval_in_page('alert("Hello PhantomJS")'); my $png = $mech->content_as_png(); print $png; # I added this line so the PNG image is sent to STDOUT
If I run that from the Linux command line like this:
  perl screenshot.pl >google.png
the resulting google.png file contains a screen shot of the google page, but there's no "Hello PhantomJS" alert on the page.  Any ideas why not, and what I should do to make the output include the alert?

I'm running WWW::Mechanize::PhantomJS 0.24 and phantomjs 2.1.1.

Thanks.
tel2

Replies are listed 'Best First'.
Re: WWW::Mechanize::PhantomJS alert not appearing in screen shot
by Corion (Patriarch) on Apr 28, 2021 at 05:57 UTC

    The alert() box is not part of the page or the HTML and is usually rendered by the browser program as a separate GUI window. You cannot capture it using the usual browser automation.

    I haven't looked at PhantomJS for a long time, so I don't remember if you can capture whether alert() was called and maybe prevent/document that.

      OK, thanks for that, Corion!