From 780b120c64a8554cfe0fc44962e36124d3f45210 Mon Sep 17 00:00:00 2001 From: ragujp Date: Sun, 26 Nov 2023 23:35:53 +0900 Subject: [PATCH] fix: wake lock error in safari etc (#12464) --- packages/frontend/src/boot/common.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/boot/common.ts b/packages/frontend/src/boot/common.ts index 12bb56a87..594fe6423 100644 --- a/packages/frontend/src/boot/common.ts +++ b/packages/frontend/src/boot/common.ts @@ -204,12 +204,16 @@ export async function common(createVue: () => App) { if (defaultStore.state.keepScreenOn) { if ('wakeLock' in navigator) { - navigator.wakeLock.request('screen'); - - document.addEventListener('visibilitychange', async () => { - if (document.visibilityState === 'visible') { - navigator.wakeLock.request('screen'); - } + navigator.wakeLock.request('screen') + .then(() => { + document.addEventListener('visibilitychange', async () => { + if (document.visibilityState === 'visible') { + navigator.wakeLock.request('screen'); + } + }); + }) + .catch(() => { + // If Permission fails on an AppleDevice such as Safari }); } }