Render JavaScript alerts

2,958 views
Skip to first unread message

Ryan Dewhurst

unread,
Jan 17, 2013, 9:36:54 AM1/17/13
to phan...@googlegroups.com
Hi,

I believe PhantomJS supports multiple windows (popups), however, these don't seem to be captured when the pages are rendered. Is this a limitation of PhantomJS or is there a way to capture the parent (main) window and the JavaScript alert window?

Thank you in advance.

Ryan

James Greene

unread,
Jan 17, 2013, 10:10:53 AM1/17/13
to phan...@googlegroups.com
I don't understand your question.  Could you please clarify what are you trying to achieve, and what issues are preventing you from achieving it?

A JavaScript alert is not a window, it's a modal dialog that is owned by a window (i.e. `window.alert("hello");`.


Sincerely,
    James Greene




Ryan

--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
Visit this group at http://groups.google.com/group/phantomjs?hl=en.
 
 

Ryan Dewhurst

unread,
Jan 17, 2013, 10:31:13 AM1/17/13
to phan...@googlegroups.com
Hi,

Apologies for for not being clear. Yes, I would like to capture the
window.alert box in a screenshot.

Thank you,
Ryan

Ivan De Marino

unread,
Jan 17, 2013, 11:54:57 AM1/17/13
to phan...@googlegroups.com
If you are interested in the content of the Alert, you can register an handler like:

    page.onAlert = function(alertMessage) { ... }

if you are interested in the actual modal window, I think there is a clear misunderstanding of what "headless" means and how our screenshot work.

We don't screenshot a "hidden" browser window: we render into a file (or a string, in case of Base64 rendering) the current webpage content rendering.
Hence, the Alert Modal Dialog/Window doesn't exist at all in PhantomJS, as it's HEADLESS: no windows are created on the desktop.

I understand that this might sound confusing, but if you use "onAlert" mentioned above, it should get much clearer.

Ryan Dewhurst

unread,
Jan 17, 2013, 12:00:19 PM1/17/13
to phan...@googlegroups.com
Hi,

We currently get the content of an alert with the onAlert callback as
you suggested but we would have liked to be able to render the model
window as well.

Yea, it seems I don't fully understand how PhantomJS works yet.

Thanks for your feedback!

Ryan

Andrew Ray

unread,
Jan 18, 2013, 5:23:05 PM1/18/13
to phan...@googlegroups.com
I had this same question a few days ago. It's not documented anywhere. Also i'm pretty sure on windows an alert box is actually a separate window? (unconfirmed, and may have changed). So that may be a point of confusion.

In fact, my issue came about because phantom was hanging, and taking a screenshot showed a perfectly normal page, but after enough investigation I found it was waiting for a confirm dialog (same mechanism as an alert) and was confused why it wouldn't show up in the screenshot.

To answer your question, no, modal dialogs (alert, confirm), will NOT show up in screenshots. If someone is comfortable editing the main wiki I think this would be good to add, because it's not obvious. it's more of an implementation thing.

is there a specific reason you want to get an actual screenshot of it? would logging the contents of the alert be a possible solution so you could view the logs along with the screenshot?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages