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
This commit is contained in:
Hendrik Luup 2024-03-05 02:16:31 +02:00 committed by GitHub
parent 04956c35b4
commit 34b8c827a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -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) =>
(