From 34b8c827a840a0bfebb4d049c2bd71e66c30513c Mon Sep 17 00:00:00 2001 From: Hendrik Luup Date: Tue, 5 Mar 2024 02:16:31 +0200 Subject: [PATCH] refactor(web): use crypto.randomUUID for UUID if available (#6649) crypto.randomUUID() is the most up to date way to generate UUIDs. It works in secure context (HTTPS) and for localhost. https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID It has a wide browser support, but we are keeping the fallback for older browsers and for cases where users are using a custom hostname without HTTPS, that's not consider a secure context. https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts --- web/src/utils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/src/utils.js b/web/src/utils.js index 0779800da..ce23b2419 100644 --- a/web/src/utils.js +++ b/web/src/utils.js @@ -140,6 +140,10 @@ export function createDialogContainer(id) { } export function makeUUID() { + if (typeof crypto.randomUUID === 'function') { + return crypto.randomUUID(); + } + // source: https://stackoverflow.com/a/2117523/6568470 return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replaceAll(/[018]/g, (c) => (