The `eyedropper-polyfill` package provides a robust polyfill for the W3C EyeDropper API, enabling developers to integrate a native-like color picking experience into web applications even in browsers that lack native support. Currently at stable version `1.1.5`, the library maintains a steady release cadence, primarily focusing on bug fixes and performance improvements as seen in recent patch releases in January 2026. Its key differentiator is its ability to replicate the EyeDropper functionality by leveraging `html2canvas-pro` internally, which allows it to capture colors from rendered web page content. This makes it a critical tool for ensuring consistent UX across a wider range of browsers, bridging compatibility gaps where the native API is not available, such as older browser versions or specific environments. It's designed for browser-side use and ships with TypeScript definitions for enhanced developer experience.
npm install eyedropper-polyfillVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize and use the EyeDropper polyfill to pick a color, including error handling for user aborts and a fallback check for API availability. It changes the background color based on selection.
Ensure `import 'eyedropper-polyfill';` is among the first statements in your application's entry point or in a script that runs early in the page load cycle.
Be aware of the Same-Origin Policy. For cross-origin content that you control, consider serving resources from the same origin or configuring appropriate CORS headers, though this may not resolve all `html2canvas-pro` limitations.
Add `"eyedropper-polyfill"` to the `types` array in your `tsconfig.json` under `compilerOptions` to include the global type definitions provided by the package.
Ensure `import 'eyedropper-polyfill';` is present and runs early in your application's lifecycle, typically in your main entry file (e.g., `index.ts` or `main.js`).
Always instantiate the EyeDropper using `new window.EyeDropper()`. Verify the polyfill has been imported correctly if `window.EyeDropper` remains undefined.
This is expected behavior for abortion. Handle this error case in your `catch` block by checking `error.name === 'AbortError'` to differentiate from other potential errors.
No dependency data recorded yet.