简体   繁体   English

使用javascript捕获网站截图

[英]Capture website screenshot using javascript

I've seen similar questions asked and the answers were not quite what I'm after. 我已经看到了类似的问题,答案并不是我所追求的。 Since this question is slightly different, I'm asking again - Hopefully you'll agree this isn't a duplicate. 由于这个问题略有不同,我再问一遍 - 希望你们同意这不是重复的。

What I want to do: Generate an image showing the contents of my own website as seen by the user (actually, each specific user). 我想做的事情:生成一个图像,显示用户看到的我自己网站的内容(实际上,每个特定用户)。

Why I want to do it: I've got some code that identifies places on the page where the user's mouse hovers for a significant length of time (ppl tend to move the mouse to areas of interest). 我为什么要这样做:我有一些代码可以识别用户鼠标在很长一段时间内徘徊的页面上的位置(ppl倾向于将鼠标移动到感兴趣的区域)。 I also record click locations. 我还记录点击位置。 These are recorded as X/Y co-ords. 这些记录为X / Y co-ords。 relative to the top-left of the page 相对于页面的左上角

NB: This is only done for users who are doing usability testing. 注意:这仅适用于进行可用性测试的用户。

I'd ideally like to be able to capture a screenshot and then use something server-side to overlay the mouse data on the image (hotspots, mouse path, etc.) 理想情况下,我希望能够捕获屏幕截图然后使用服务器端的东西来覆盖图像上的鼠标数据(热点,鼠标路径等)

The problem I have is that page content is very dynamic (not so much during display but during server-side generation) - depending on the type of user, assigned roles, etc... whole boxes can be missing - and the rest of the layout readjusts accordingly - consequently there's no single "right" screenshot for a page. 我遇到的问题是页面内容非常动态(在显示期间不是很多,但在服务器端生成期间) - 取决于用户类型,分配的角色等等...整个框可能会丢失 - 其余的布局相应地重新调整 - 因此页面没有单一的“右”屏幕截图。

Option 1 (which feels a little nasty): would be to walk the DOM and serialize it and send that back to the server. 选项1(感觉有点讨厌):将走DOM并将其序列化并将其发送回服务器。 I'd then open up the appropriate browser and de-serialize the DOM. 然后我打开适当的浏览器并反序列化DOM。 This should work but sounds difficult to automate. 这应该工作,但听起来很难自动化。 I suspect there'd also be some issues around relative URLs, etc. 我怀疑相对URL等问题也存在一些问题。

Option 2: Once the page has finished loading, capture an image of the client area (I'd ideally like to capture the whole length of the page but suspect this will be even harder). 选项2:页面加载完成后,捕获客户区域的图像(理想情况下,我想捕获页面的整个长度,但怀疑这将更难)。 Most pages don't require scrolling so this shouldn't be a major issue - something to improve for version 2. I'd then upload this image to the server via AJAX. 大多数页面不需要滚动,因此这不应该是一个主要问题 - 需要改进版本2.然后我会通过AJAX将此图像上传到服务器。

NB: I don't want to see anything outside the contents of my own page (chrome, address bar, anything) 注意:我不希望看到我自己页面内容之外的任何内容(chrome,地址栏,任何内容)

I'd prefer to be able to do this without installing anything on the end-user pc (hence javascript). 我宁愿能够在没有在最终用户PC上安装任何东西的情况下这样做(因此javascript)。 If the only possibility is a client-side app, we can do that but it will mean more hassle when getting random users to usability test (currently, we just email friends/family/guinea pigs a different URL) 如果唯一的可能性是客户端应用程序,我们可以做到这一点,但当将随机用户进行可用性测试时,这将意味着更麻烦(目前,我们只是向朋友/家人/豚鼠发送不同的URL)

One alternative solution would be to "record" the positions and dimensions of the main structural elements on the page: 一种替代解决方案是“记录”页面上主要结构元素的位置和尺寸:

(using jQuery) (使用jQuery)

var pageStructure = {};

$("#header, #navigation, #sidebar, #article, #ad, #footer").each(function() {
    var elem = $(this);
    var offset = elem.offset();
    var width = elem.outerWidth();
    var height = elem.outerHeight();
    pageStructure[this.id] = [offset.left, offset.top, width, height];
});

Then you send the serialized pageStructure along with the mouse-data, and based on that data you can reconstruct the layout of the given page. 然后将序列化的pageStructure与鼠标数据一起发送,并根据该数据重建给定页面的布局。

One thing we always talk about where I work is the value of ownership vs the cost required to make something from scratch. 我们总是谈论我工作的一件事是所有权的价值与从头开始制作东西所需的成本。 With the group I have, we could build just about anything...however, at a per-hour rate in the $100 range, it would need to be a pretty marketable tool or replace a very expensive product for it to be worth our time. 对于我所拥有的团队,我们可以构建几乎任何东西......但是,在100美元范围内的每小时费率,它需要是一个非常有市场的工具或替换非常昂贵的产品,因为它值得我们的时间。 So, when it comes to things like this that are already done, I'd consider looking elsewhere first. 所以,当涉及到这样的事情已经完成时,我会先考虑在别处寻找。 Think of what you could do with all that extra time.... 想想你可以用额外的时间做些什么....

A simple, quick google search found this: http://www.trymyui.com/ It's likely not perfect, but it points to the fact that solutions like this are out there and already working/tested. 一个简单,快速的谷歌搜索发现这个: http//www.trymyui.com/它可能不完美,但它指出这样的事实,像这样的解决方案已经工作/测试。 Or, you could download a script such as this heatmap Obviously, you'd need to add a bit to allow you to re-create what was on the screen while the map was created. 或者,您可以下载此热图等脚本显然,您需要添加一些内容,以便在创建地图时重新创建屏幕上的内容。

Good Luck. 祝好运。

IMO, it's not worth reinventing the wheel. IMO,不值得重新发明轮子。 Just buy an existing solution like ClickTale. 只需购买像ClickTale这样的现有解决方案。

http://www.clicktale.com/ http://www.clicktale.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM