loading
Warning:
Experimental - Chromium desktop only The EyeDropper API is experimental and currently implemented only in Chromium-based desktop browsers (Chrome, Edge, Opera). Firefox, Safari and mobile browsers do not support it - always gate usage behind IsSupported.
Note:
User gesture requiredOpen must be called from a user-gesture handler such as a button click - the browser rejects the request otherwise. The user can cancel the picker at any time with Esc, in which case Open returns null.

Support check

IsSupported

Returns true when the runtime exposes window.EyeDropper. During prerender/SSR the check returns false rather than throwing, so defer it to OnAfterRenderAsync.

C#
@inject Bit.Butil.EyeDropper eyeDropper

var supported = await eyeDropper.IsSupported();
Live sample
support check output
Results will appear here when you interact with the samples.

Pick a color

Open

Opens the eyedropper cursor and resolves with the picked sRGB color in hex form (for example #1f2937). The cursor can sample any pixel on the screen, including other applications. A null result means the user cancelled or the runtime couldn't show the picker.

C#
var hex = await eyeDropper.Open();

if (hex is not null)
{
    // hex == "#1f2937" - feed it straight into a style or a theme
}
Live sample
pick color output
Results will appear here when you interact with the samples.

Handle cancellation

Open

Unlike the raw JS API, which rejects the promise on cancel, Butil normalizes both cancellation and picker failures to a null return - so no try/catch is needed for the common flow. A try/catch remains a good idea for unexpected interop failures.

C#
var hex = await eyeDropper.Open();

if (hex is null)
{
    // user pressed Esc, or the picker couldn't be shown
    return;
}

ApplyAccentColor(hex);

API reference

Member
Signature
Description
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes window.EyeDropper.
Open
ValueTask<string?> Open()
Opens the eyedropper and returns the picked sRGB color in hex form (e.g. #1f2937). Returns null when the user cancels or the runtime can't show the picker. Must be called from a user-gesture handler.
An unhandled error has occurred. Reload 🗙