2

I know you can render/rasterize a web page to image or PDF in PhantomJS, but is there a way to do it inside a browser like for example on iframe, to use PhantomJS as an engine to show the source in a browser?

I need the render to be interactive

Thanks in advance!

moonman
  • 21
  • 2
  • I'm not sure what you mean. You want to show the rendered page of PhantomJS in a non-headless browser? You talk about source. Do you mean that the source that PhantomJS produced is rendered in the non-headless browser or do you mean that the page is rendered in PhantomJS and the image is shown in the non-headless browser? – Artjom B. Feb 06 '15 at 10:28
  • Yes I want to show the rendered page of PhantomJS in a non-headless browser – moonman Feb 06 '15 at 10:30
  • I see. Well, you will have to do it yourself, because the question is too broad. We can't give you code when you didn't even specify what server environment you use. What kind of answers are you looking for, because PhantomJS is a commanline tool and cannot be run in another browser? – Artjom B. Feb 06 '15 at 10:34
  • I just need to know if there is a way to get a realtime view of what PhantomJS is rendering in a non-headless browser, if there is some kind of API for it? – moonman Feb 06 '15 at 10:42
  • possible duplicate of [Installing PhantomJS on server](http://stackoverflow.com/questions/26896787/installing-phantomjs-on-server); No, there isn't. – Artjom B. Feb 06 '15 at 10:45
  • No he is asking if he can take a url as input and return an image file of the screen shot of the website, but i need to see a realtime render like im using a non-headless browser – moonman Feb 06 '15 at 10:49
  • You mean a "video"? This is nothing other than a string of images which can be requested from the server. – Artjom B. Feb 06 '15 at 10:54
  • No i need the render to be interactive not images. – moonman Feb 06 '15 at 11:01
  • Then please clarify this in your question by editing it. The answer is: **No, it is not possible.** – Artjom B. Feb 06 '15 at 11:04
  • 1
    why not use a browser? – atmd Feb 06 '15 at 11:14

1 Answers1

1

There is no built-in way of doing this and especially not in an interactive fashion. PhantomJS is headless browser, but a complete browser nonetheless. It cannot be simply put into another browser without much much work.

One could for example try to use emscripten to compile PhantomJS into pure JavaScript which can then be directly executed in a non-headless browser.

Another idea would be to use a server environment to run a PhantomJS instance, send commands to this instance through AJAX and receive the rendered output. Some suggestions here.

You would then need to add event handling on the page that displays the rendered images. Those are basically keyboard and mouse events which can be send to the server/converted process which then executes those commands through page.sendEvent(), renders the page again and sends it to the non-headless browser.

I doubt this is at all practical. You can try to use Chrome 13 to simply simulate the PhantomJS 1.x or Chrome 37/38 to simulate PhantomJS 2.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222