有没有一种方法可以在浏览器中直观地查看PhantomJS渲染的内容 [英] Is there a way to visually see what has been render by PhantomJS on a Browser

查看:183
本文介绍了有没有一种方法可以在浏览器中直观地查看PhantomJS渲染的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以在PhantomJS中将网页渲染/光栅化为图像或PDF,但是有一种方法可以在浏览器中(例如在iframe上)使用PhantomJS作为引擎在浏览器中显示源?

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?

我需要交互式渲染

提前谢谢!

推荐答案

没有内置方法可以做到这一点,尤其是不能以交互方式进行. PhantomJS是无头浏览器,但是仍然是完整的浏览器.没有太多工作就不能简单地将其放入另一个浏览器.

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.

例如,可以尝试使用emscripten将PhantomJS编译为纯JavaScript,然后可以在无头浏览器中直接执行该

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.

另一个想法是使用服务器环境来运行PhantomJS实例,通过AJAX向该实例发送命令并接收渲染的输出.一些建议此处.

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.

然后,您需要在显示渲染图像的页面上添加事件处理.这些基本上是键盘和鼠标事件,可以发送到服务器/转换后的进程,然后通过 page.sendEvent() ,再次呈现页面并将其发送到无头浏览器.

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.

我怀疑这是完全可行的.您可以尝试使用Chrome 13来简单地模拟PhantomJS 1.x或使用Chrome 37/38来模拟PhantomJS 2.

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.

这篇关于有没有一种方法可以在浏览器中直观地查看PhantomJS渲染的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆