diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index 9dad208..5908eb2 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -122,8 +122,9 @@ export async function clipboardSupported(): Promise { 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 { } return false; } + +export function timeout(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +}