From a961f5a017488d48b10bdf4cb1ce872de367fc62 Mon Sep 17 00:00:00 2001 From: Thorn Walli Date: Sun, 18 Aug 2024 23:35:31 +0200 Subject: [PATCH 1/2] fix(entry): added revoke --- playground/nuxt.config.js | 10 ++++++---- src/runtime/utils/entry.js | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/playground/nuxt.config.js b/playground/nuxt.config.js index 5d7e244ddf..3f744aaf64 100644 --- a/playground/nuxt.config.js +++ b/playground/nuxt.config.js @@ -133,10 +133,12 @@ export default defineNuxtConfig(async () => { // inlineStyles: true // }, - detection: { - performance: true, - browserSupport: true - }, + // detection: { + // performance: true, + // browserSupport: true, + // battery: true + // }, + performanceMetrics: { device: { hardwareConcurrency: { min: 2, max: 48 }, diff --git a/src/runtime/utils/entry.js b/src/runtime/utils/entry.js index eb3f854ac9..a7953c18c4 100644 --- a/src/runtime/utils/entry.js +++ b/src/runtime/utils/entry.js @@ -93,11 +93,19 @@ const isBatteryLow = async () => { * In this case no video will be played automatically and play throws an error. */ export const canVideoPlay = blob => { - const video = document.createElement('video'); - video.muted = true; - video.playsinline = true; - video.src = URL.createObjectURL(blob); - return video.play(); + const objectUrl = URL.createObjectURL(blob); + try { + const video = document.createElement('video'); + video.muted = true; + video.playsinline = true; + video.src = objectUrl; + const result = video.play(); + URL.revokeObjectURL(objectUrl); + return result; + } catch (error) { + URL.revokeObjectURL(objectUrl); + throw error; + } }; export const deprecationWarningButtonSelector = initApp => { From 89ce7dfc9a2272861a92ea9d43224b333da8ed32 Mon Sep 17 00:00:00 2001 From: Thorn Walli Date: Sun, 18 Aug 2024 23:39:21 +0200 Subject: [PATCH 2/2] fix(entry): fix missing await --- src/runtime/utils/entry.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/runtime/utils/entry.js b/src/runtime/utils/entry.js index a7953c18c4..afb868bc67 100644 --- a/src/runtime/utils/entry.js +++ b/src/runtime/utils/entry.js @@ -92,16 +92,15 @@ const isBatteryLow = async () => { * * In this case no video will be played automatically and play throws an error. */ -export const canVideoPlay = blob => { +export const canVideoPlay = async blob => { const objectUrl = URL.createObjectURL(blob); try { const video = document.createElement('video'); video.muted = true; video.playsinline = true; video.src = objectUrl; - const result = video.play(); + await video.play(); URL.revokeObjectURL(objectUrl); - return result; } catch (error) { URL.revokeObjectURL(objectUrl); throw error;