Fix document not focused error on clipboard permission accept Windows

This commit is contained in:
Nicola Thouliss 2021-08-20 23:28:00 +10:00 committed by Mitchell McCaffrey
parent c767f35590
commit 91f44f9eda

View File

@ -122,8 +122,9 @@ export async function clipboardSupported(): Promise<boolean> {
try {
await navigator.clipboard.readText();
query = await navigator.permissions.query({ name: "clipboard-read" });
// Focus window after permission dialog closed to allow further calls the api
window.focus();
// Wait 300ms before returning when permission has been accepted to prevent immediate calls
// to the clipboard api to fail with a document not focused error
await timeout(300);
} catch {
return false;
}
@ -133,3 +134,7 @@ export async function clipboardSupported(): Promise<boolean> {
}
return false;
}
export function timeout(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}