Skip to content

Commit 9a01e4d

Browse files
committed
Fix for non https
1 parent c87eb7a commit 9a01e4d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import { App } from './App';
44
import '@webview/index.css';
55
import './styles/web-theme.css';
66

7+
// Polyfill crypto.randomUUID for non-secure contexts (HTTP).
8+
// Mobile browsers only expose randomUUID() over HTTPS, but
9+
// crypto.getRandomValues() works everywhere.
10+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID !== 'function') {
11+
crypto.randomUUID = () =>
12+
'10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => {
13+
const n = Number(c);
14+
return (n ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (n / 4)))).toString(16);
15+
}) as `${string}-${string}-${string}-${string}-${string}`;
16+
}
17+
718
localStorage.setItem('editor', JSON.stringify('web'));
819
document.documentElement.dataset.editor = 'web';
920
window.mediaUrl = '';

0 commit comments

Comments
 (0)