Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@gitee/html2canvas

niklasvh103MIT1.3.3-2TypeScript support: included

Screenshots with JavaScript

readme

html2canvas

Homepage | Downloads | Questions

Gitter CI 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.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.3.3 (2021-11-23)

ci

fix

1.3.2 (2021-08-15)

docs

  • add warning for webgl cloning with preserveDrawingBuffer=false (#2661) (01ed879), closes #2661
  • include src files on www (#2660) (58ff000), closes #2660

feat

  • add support for data-html2canvas-debug property for debugging (#2658) (cd0d725), closes #2658

fix

  • disable transition properties (#2659) (f143166), closes #2659
  • overflows with absolutely positioned content (#2663) (38c6829), closes #2663

1.3.1 (2021-08-14)

fix

  • multi arg transition/animation duration (#2657) (1b55ed5), closes #2657

1.3.0 (2021-08-13)

feat

fix

  • correctly handle allowTaint canvas cloning (#2649) (c378e22), closes #2649
  • finish animation/transitions for elements (#2632) (969638f), closes #2632

test

  • add letter-spacing test for zwj emoji (#2650) (f919204), closes #2650

1.2.2 (2021-08-10)

ci

docs

fix

  • parsing counter content in pseudo element (#2640) (1941b9e), closes #2640
  • radial gradient ry check (#2631) (a0dd38a), closes #2631
  • test for ios range line break error (#2635) (f43f942), closes #2635

test

  • large base64 encoded background (#2636) (e36408a), closes #2636

1.2.1 (2021-08-05)

fix

  • none image (#2627) (6651fc6), closes #2627
  • type import that is only available ts 3.8 or higher (#2629) (c5c6fa0), closes #2629

1.2.0 (2021-08-04)

fix

test

  • element with scrolled window (#2624) (1338c7b), closes #2624

1.1.5 (2021-08-02)

docs

  • update README to github discussion Q/A (5dea36b)

fix

1.1.4 (2021-07-15)

feat

  • add support for webkit-text-stroke and paint-order (#2591) (522e5aa), closes #2591

fix

  • don't copy 'all' css property (#2586) (fa60716), closes #2586
  • svg d path getting truncated on copy (#2589) (dd6d885), closes #2589
  • text position for form elements and list markers (#2588) (cd99f11), closes #2588
  • this.canvas.ownerDocument is undefined (#2590) (45efe54), closes #2590
  • word-break seperators (#2593) (e9f7f48), closes #2593

test

  • refactor language tests (#2594) (4c360fc), closes #2594
  • update box-shadow with radius (578bb77)

1.1.3 (2021-07-14)

feat

  • allow access to reference element in onclone (#2584) (58b4591), closes #2584
  • support for custom and slot elements (#2581) (acb4cd2), closes #2581

fix

  • iframe load to ensure images are loaded (#2577) (eeb5a3e), closes #2577
  • image blob rendering (1acdc82)
  • responsive svg images (#2583) (92fa448), closes #2583

test

  • add test cases for text-stroke and textarea from (#1540 and #2132) (#2585) (1d00bfe), closes #1540 #2132 #2585

1.1.2 (2021-07-13)

ci

  • implement screenshot diffing (#2571) (e29af58), closes #2571

fix

  • logger unique names (#2575) (1715854), closes #2575
  • text-shadow position with baseline (#2576) (439e365), closes #2576

1.1.1 (2021-07-12)

fix

  • allow proxy url with parameters (#2100) (a4a3ce8), closes #2100
  • crash on background-size with calc() (fix #2469) (#2569) (084017a), closes #2469 #2569
  • handle unhandled promise rejections (#2568) (4555940), closes #2568

1.1.0 (2021-07-11)

ci

  • fail build if no artifacts uploaded (#2566) (e7a021a), closes #2566

deps

  • update dependencies with lint fixes (#2565) (b2902ec), closes #2565

docs

  • update border-style support (cf35a28)

fix

  • Ensure resizeImage's canvas has at least 1px of width and height (#2409) (bb92371), closes #2409
  • text-decoration-line fallback (#2088) (#2567) (44296e5), closes #2088 #2567
  • use baseline for text positioning (#2109) (85f79c1), closes #2109

1.0.0 (2021-07-04)

ci

  • update docs publish action (#2451) (7222aba), closes #2451

deps

feat

  • add support for border-style dashed, dotted, double (#2531) (72cd528)

fix

  • opacity with overflow hidden (#2450) (82b7da5), closes #2450
  • top right border radius (#2522) (ba17267)

test

1.0.0-rc.7 (2020-08-09)

fix

  • concatenate contiguous font-family tokens (#2219) (bacfadf), closes #2219
  • external styles on svg elements (#2320) (1514220), closes #2320

1.0.0-rc.6 (2020-08-08)

ci

  • Azure Pipelines: upgrade from macOS 10.13 -> 10.14 (#2204) (c366e87), closes #2204
  • build docs (#2305) (51de347), closes #2305

fix

1.0.0-rc.5 (2019-09-27)

fix

1.0.0-rc.4 (2019-09-22)

docs

feat

fix

1.0.0-rc.3 (2019-05-30)

fix

1.0.0-rc.2 (2019-05-29)

ci

docs

fix

test

1.0.0-rc.1 (2019-04-10)

ci

docs

fix

test

1.0.0-rc.0 (2019-04-07)

build

ci

docs

fix

1.0.0-alpha.12 (2018-04-05)

  • Fix white space appearing on element rendering (Fix #1438)
  • Reset canvas transform on finish (Fix #1494)

v1.0.0-alpha.11 - 1.4.2018

  • Fix IE11 member not found error
  • Support blob image resources in non-foreignObjectRendering mode

v1.0.0-alpha.10 - 15.2.2018

  • Re-introduce onclone option (Fix #1434)
  • Add ignoreElements predicate function option
  • Fix version console logging

v1.0.0-alpha.9 - 7.1.2018

  • Fix dynamic style sheets
  • Fix > 50% border-radius values

v1.0.0-alpha.8 - 2.1.2018

  • Use correct doctype in cloned Document (Fix #1298)
  • Fix individual border rendering (Fix #1349)

v1.0.0-alpha.7 - 31.12.2017

  • Fix form input rendering (#1338)
  • Improve word line breaking algorithm

v1.0.0-alpha.6 - 28.12.2017

  • Fix list-style: none (#1340)
  • Extend supported values for pseudo element content

v1.0.0-alpha.5 - 21.12.2017

  • Fix underline positioning
  • Fix canvas rendering on Chrome
  • Fix overflow: auto
  • Added support for rendering list-style

    v1.0.0-alpha.4 - 12.12.2017

  • Fix rendering with multiple fonts defined (Fix #796)
  • Add support for radial-gradients
  • Fix logging option (#1302)
  • Add support for rendering webgl canvas content (#646)
  • Fix external SVG loading with proxies (#802)

v1.0.0-alpha.3 - 9.12.2017

  • Disable foreignObjectRendering by default (#1295)
  • Fix background-size when using background-origin and background-size: cover/contain (#1299)
  • Added support for background-origin: content-box (#1299)

v1.0.0-alpha.2 - 7.12.2017

  • Fix scroll positions for CanvasRenderer (#1259)
  • Fix data-html2canvas-ignore attribute (#1253)
  • Fix decimal letter-spacing values (#1293)

v1.0.0-alpha.1 - 5.12.2017

  • Complete rewrite of library
    Breaking Changes
  • Remove deprecated onrendered callback, calling html2canvas returns a Promise<HTMLCanvasElement>
  • Removed option type, same results can be achieved by assigning x, y, scrollX, scrollY, width and height properties.

    New featues / fixes

  • Add support for scaling canvas (defaults to device pixel ratio)
  • Add support for multiple text-shadows
  • Add support for multiple text-decorations
  • Add support for text-decoration-color
  • Add support for percentage values for border-radius
  • Correctly handle px and percentage values in linear-gradients
  • Correctly support all angle types for linear-gradients
  • Add support for multiple values for background-repeat, background-position and background-size

v0.5.0-beta4 - 23.1.2016

  • Fix logger requiring access to window object
  • Derequire browserify build
  • Fix rendering of specific elements when window is scrolled and type isn't set to view

v0.5.0-beta3 - 6.12.2015

  • Handle color names in linear gradients

v0.5.0-beta2 - 20.10.2015

  • Remove Promise polyfill (use native or provide it yourself)

v0.5.0-beta1 - 19.10.2015

  • Fix bug with unmatched color stops in gradients
  • Fix scrolling issues with iOS
  • Correctly handle named colors in gradients
  • Accept matrix3d transforms
  • Fix transparent colors breaking gradients
  • Preserve scrolling positions on render

v0.5.0-alpha2 - 3.2.2015

  • Switch to using browserify for building
  • Fix (#517) Chrome stretches background images with 'auto' or single attributes

v0.5.0-alpha - 19.1.2015

  • Complete rewrite of library
  • Switched interface to return Promise
  • Uses hidden iframe window to perform rendering, allowing async rendering and doesn't force the viewport to be scrolled to the top anymore.
  • Better support for unicode
  • Checkbox/radio button rendering
  • SVG rendering
  • iframe rendering
  • Changed format for proxy requests, permitting binary responses with CORS headers as well
  • Fixed many layering issues (see z-index tests)

v0.4.1 - 7.9.2013

  • Added support for bower
  • Improved z-index ordering
  • Basic implementation for CSS transformations
  • Fixed inline text in top element
  • Basic implementation for text-shadow

v0.4.0 - 30.1.2013

  • Added rendering tests with webdriver
  • Switched to using grunt for building
  • Removed support for IE<9, including any FlashCanvas bits
  • Support for border-radius
  • Support for multiple background images, size, and clipping
  • Support for :before and :after pseudo elements
  • Support for placeholder rendering
  • Reformatted all tests to small units to test specific features

v0.3.4 - 26.6.2012

  • Removed (last?) jQuery dependencies (niklasvh)
  • SVG-powered rendering (niklasvh)
  • Radial gradients (SunboX)
  • Split renderers to their own objects (niklasvh)
  • Simplified API, cleaned up code (niklasvh)

v0.3.3 - 2.3.2012

  • SVG taint fix, and additional taint testing options for rendering (niklasvh)
  • Added support for CORS images and option to create canvas as tainted (niklasvh)
  • Improved minification saved ~1K! (cobexer)
  • Added integrated support for Flashcanvas (niklasvh)
  • Fixed a variety of legacy IE bugs (niklasvh)

v0.3.2 - 20.2.2012

  • Added changelog!
  • Added bookmarklet (cobexer)
  • Option to select single element to render (niklasvh)
  • Fixed closure compiler warnings (cobexer)
  • Enable profiling in FF (cobexer)