html2canvas-pro is an actively maintained fork of the popular `niklasvh/html2canvas` library, designed to capture screenshots of web pages or specific DOM elements using JavaScript. It is currently at version 2.0.2 and appears to have a consistent release cadence with several recent patch releases following a major version bump to 2.0.0. Key differentiators include enhanced support for modern CSS color functions like `color()`, `lab()`, `lch()`, `oklab()`, and `oklch()`, improved handling of `object-fit` for images, and explicit control over image smoothing via the `image-rendering` CSS property or a global option. This package aims to address various issues and provide advanced features beyond the original `html2canvas` project, making it suitable for complex screenshot requirements where standard `html2canvas` might fall short. It ships with TypeScript types for improved developer experience.
npm install html2canvas-proVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to capture a screenshot of the document body or a specific element, append the generated canvas to the DOM, and control output dimensions and image format.
To achieve exact pixel dimensions for the output canvas, specify both `width` and `height` options in the configuration object and set `scale: 1`. Example: `html2canvas(element, { width: 1920, height: 1080, scale: 1 });`Ensure all assets (images, fonts) are served from the same origin as the page. If cross-origin resources must be used, they require appropriate CORS headers (`Access-Control-Allow-Origin`) and the `useCORS: true` option. For iframes, they must be same-origin and iframed with the `allow-same-origin` sandbox attribute.
Ensure all images and resources within the captured element are served from the same domain or configured with CORS headers. Set `useCORS: true` in the `html2canvas` options if resources have valid CORS headers. Consider using a proxy to fetch cross-origin images if direct CORS is not possible.
Verify that `import html2canvas from 'html2canvas-pro';` is at the top of your module. If using CommonJS, ensure `const html2canvas = require('html2canvas-pro');` is used. In a browser environment without a bundler, confirm the script tag for `html2canvas-pro` is correctly included and loaded before the function is called.Wrap your `html2canvas` call in a DOMContentLoaded listener or ensure it runs after the target element is guaranteed to exist in the DOM. For example: `document.addEventListener('DOMContentLoaded', () => { html2canvas(document.body).then(...) });`No dependency data recorded yet.