Types don't reflect that clipboard is undefined in insecure contexts
Closed this issue · 1 comments
The referenced w3 API specifies:
partial interface [Navigator](https://html.spec.whatwg.org/multipage/system-state.html#navigator) {
[[SecureContext](https://webidl.spec.whatwg.org/#SecureContext), [SameObject](https://webidl.spec.whatwg.org/#SameObject)] readonly attribute [Clipboard](https://www.w3.org/TR/clipboard-apis/#clipboard) [clipboard](https://www.w3.org/TR/clipboard-apis/#dom-navigator-clipboard);
};
and sure enough, on insecure pages (with window.isSecureContext === false) like about:blank (or any other HTTP pages), window.clipboard is undefined.
For me, this meant that calling writeText caused my Effect computation to abort (with no error!) See screenshot:
I am not sure what the right way to address this should be. Should clipboard have type Window -> Maybe Clipboard instead? Internally, it could check for undefined. That might be more robust than checking isSecureContext.
Yeah, that would work, or possibly have clipboard throw an exception... that would avoid breaking the interface and make it more convenient for the cases where it's not expected to run in an insecure context. But the Maybe is probably the better option, since exceptions are invisible in the API other than the standard caveat that anything that happens in Effect might throw an exception... but nobody (including myself) thinks about that often.
