EyeDropper: open() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheEyeDropper.open() method starts the eyedropper mode, returning a promise which is fulfilled once the user has selected a color and exited the eyedropper mode.
In this article
Syntax
open()open(options)Parameters
optionsOptionalAn options object to pass an
AbortSignalsignal:signalOptionalAn
AbortSignal. The eyedropper mode will be aborted when theAbortSignal'sabort()method is called.
Return value
APromise that eventually resolves when the user selects a pixel color from the screen.
The promise resolves to an object with the following property:
sRGBHexA string representing the selected color, in hexadecimal sRGB format (
#aabbcc).
Exceptions
Exceptions are not thrown but returned when thePromise is rejected.
NotAllowedErrorDOMExceptionThrown if
open()is not called via atransient user activation.InvalidStateErrorDOMExceptionThrown if another eye dropper has already opened.
AbortErrorDOMExceptionThrown if the user aborts the selection by pressing theEsc key or if the selection is aborted by an
AbortControllerbeing passed as an argument toopen().OperationErrorDOMExceptionThrown if the selection fails for other reasons.
Specifications
| Specification |
|---|
| EyeDropper API> # dom-eyedropper-open> |
Browser compatibility
See also
- The
EyeDropperinterface it belongs to.