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

Retrieving content of console log of webshot #98

Open
DerekDomino opened this issue Feb 13, 2015 · 1 comment
Open

Retrieving content of console log of webshot #98

DerekDomino opened this issue Feb 13, 2015 · 1 comment

Comments

@DerekDomino
Copy link

Hello,

Is there a way to get back the content of the messages logged to the console by the frontend-level javascript run by webshot?

I would like to debug javascript code run by webshot.

Thanks

@LorenzGardner
Copy link
Contributor

Yes, and No. There isn't a built in option for webshot, but it is a feature of phantomJS so you can get ot it with minimal effort. I've done it a few times now.

You need to open up the webshot.phantom.js, and modify the code to add a listener to the page object for the onConsoleMessage event from phatomjs. Simply adding a console.log to that handler should do. Note, that only the msg argument is currently used, you will always get undefined for the others (line number and source id).

For reference here is the error handler you might want to stick a console.log into: https://github.com/brenden/node-webshot/blob/master/lib/webshot.phantom.js#L24

And you can also add a onConsoleMessage listener right bellow that. Documentation on that here:
http://phantomjs.org/api/webpage/handler/on-console-message.html

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

No branches or pull requests

2 participants