Skip to content

Commit 774d7d2

Browse files
author
Hiram
committed
[optimize] crypto.randomUUID compatibility
1 parent 918aad0 commit 774d7d2

File tree

1 file changed

+7
-1
lines changed
  • apps/cookie-butler/static/js

1 file changed

+7
-1
lines changed

Diff for: apps/cookie-butler/static/js/core.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ class QRCodeHandler {
2929
}
3030

3131
static generateUUID() {
32-
return crypto.randomUUID();
32+
if (crypto && typeof crypto.randomUUID === 'function') {
33+
return crypto.randomUUID();
34+
} else {
35+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
36+
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
37+
);
38+
}
3339
}
3440

3541
async _generateQRCode(url) {

0 commit comments

Comments
 (0)