html2canvas

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

  • 所有者: niklasvh/html2canvas
  • 平台: Web browsers
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    2
      比較:

Github星跟蹤圖

JavaScript HTML渲染器。

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

它是如何工作的?

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

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

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

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

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

概覽

名稱與所有者niklasvh/html2canvas
主編程語言TypeScript
編程語言JavaScript (語言數: 4)
平台Web browsers
許可證MIT License
發布數50
最新版本名稱v1.4.1 (發布於 2022-01-22 16:19:57)
第一版名稱0.3.0 (發布於 )
創建於2011-07-16 01:05:58
推送於2024-05-18 13:52:06
最后一次提交2022-01-23 00:27:44
星數29.9k
關注者數509
派生數4.7k
提交數1.1k
已啟用問題?
問題數2563
打開的問題數911
拉請求數186
打開的拉請求數71
關閉的拉請求數232
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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.

去到頂部