From 91f44f9edaa7db036ad5c1e3b89035d891e4f7b7 Mon Sep 17 00:00:00 2001 From: Nicola Thouliss <53867736+nthouliss@users.noreply.github.com> Date: Fri, 20 Aug 2021 23:28:00 +1000 Subject: [PATCH] Fix document not focused error on clipboard permission accept Windows --- src/helpers/shared.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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)); +}