html2canvas

使用JavaScript截图。(Screenshots with JavaScript. )

  • Owner: niklasvh/html2canvas
  • Platform: Web browsers
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    2
      Compare:

Github stars Tracking Chart

JavaScript HTML渲染器。

该脚本允许您直接在用户浏览器上截取网页或部分网页的“屏幕截图”。屏幕截图基于DOM,因此它可能不是真实表示的100%准确,因为它没有制作实际的屏幕截图,而是根据页面上可用的信息构建屏幕截图。

它是如何工作的?

该脚本通过读取DOM以及应用于元素的不同样式,将当前页面呈现为画布图像。
它不需要从服务器进行任何渲染,因为整个图像是在客户端的浏览器上创建的。但是,由于它严重依赖于浏览器,因此该库不适合在nodejs中使用。它也不会神奇地规避任何浏览器内容策略限制,因此呈现跨源内容将需要代理才能将内容提供给相同的源。

该脚本仍处于非常实验状态,因此我不建议在生产环境中使用它,也不建议使用它来构建应用程序,因为仍然会有重大更改。浏览器兼容性

该库应该可以在以下浏览器上正常工作(使用Promise polyfill):

  • Firefox 3.5+
  • 谷歌浏览器
  • Opera 12+
  • IE9 +
  • Safari 6+

由于需要手动构建每个CSS属性以支持,因此还有许多尚不支持的属性。

Overview

Name With Ownerniklasvh/html2canvas
Primary LanguageTypeScript
Program languageJavaScript (Language Count: 4)
PlatformWeb browsers
License:MIT License
Release Count50
Last Release Namev1.4.1 (Posted on 2022-01-22 16:19:57)
First Release Name0.3.0 (Posted on )
Created At2011-07-16 01:05:58
Pushed At2024-04-20 02:40:38
Last Commit At2022-01-23 00:27:44
Stargazers Count29.8k
Watchers Count510
Fork Count4.7k
Commits Count1.1k
Has Issues Enabled
Issues Count2560
Issue Open Count909
Pull Requests Count186
Pull Requests Open Count70
Pull Requests Close Count231
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

html2canvas

Homepage, Downloads, Questions

Gitter
Build Status
NPM Downloads
NPM Version

JavaScript HTML renderer

The script allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.

How does it work?

The script renders the current page as a canvas image, by reading the DOM and the different styles applied to the elements.

It does not require any rendering from the server, as the whole image is created on the client's browser. However, as it is heavily dependent on the browser, this library is not suitable to be used in nodejs.
It doesn't magically circumvent any browser content policy restrictions either, so rendering cross-origin content will require a proxy to get the content to the same origin.

The script is still in a very experimental state, so I don't recommend using it in a production environment nor start building applications with it yet, as there will be still major changes made.

Browser compatibility

The library should work fine on the following browsers (with Promise polyfill):

  • Firefox 3.5+
  • Google Chrome
  • Opera 12+
  • IE9+
  • Safari 6+

As each CSS property needs to be manually built to be supported, there are a number of properties that are not yet supported.

Usage

The html2canvas library utilizes Promises and expects them to be available in the global context. If you wish to
support older browsers that do not natively support Promises, please include a polyfill such as
es6-promise before including html2canvas.

To render an element with html2canvas, simply call:
html2canvas(element[, options]);

The function returns a Promise containing the <canvas> element. Simply add a promise fulfillment handler to the promise using then:

html2canvas(document.body).then(function(canvas) {
    document.body.appendChild(canvas);
});

Building

You can download ready builds here.

Clone git repository:

$ git clone git://github.com/niklasvh/html2canvas.git

Install dependencies:

$ npm install

Build browser bundle

$ npm run build

Examples

For more information and examples, please visit the homepage or try the test console.

Contributing

If you wish to contribute to the project, please send the pull requests to the develop branch. Before submitting any changes, try and test that the changes work with all the support browsers. If some CSS property isn't supported or is incomplete, please create appropriate tests for it as well before submitting any code changes.

To the top