File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change 88< div id ="reader "> </ div >
99
1010< script >
11- function onScanSuccess ( decodedText ) {
12- if ( decodedText . includes ( 'gptgames.dev' ) ) {
13- window . location . href = decodedText ;
11+ async function startScanner ( ) {
12+ try {
13+ // Check if we already have camera permission
14+ const stream = await navigator . mediaDevices . getUserMedia ( { video : true } ) ;
15+ stream . getTracks ( ) . forEach ( track => track . stop ( ) ) ; // Clean up test stream
16+
17+ // Initialize scanner
18+ const html5QrcodeScanner = new Html5QrcodeScanner ( "reader" , { fps : 10 } ) ;
19+ html5QrcodeScanner . render ( ( decodedText ) => {
20+ if ( decodedText . includes ( 'gptgames.dev' ) ) {
21+ window . location . href = decodedText ;
22+ }
23+ } ) ;
24+ } catch ( err ) {
25+ // We don't have permission, let's request it
26+ const permissionResult = await navigator . mediaDevices . getUserMedia ( { video : true } ) ;
27+ // If we get here, permission was granted, start scanner
28+ startScanner ( ) ;
1429 }
1530 }
1631
17- let html5QrcodeScanner = new Html5QrcodeScanner (
18- "reader" ,
19- { fps : 10 }
20- ) ;
21-
22- html5QrcodeScanner . render ( onScanSuccess ) ;
32+ // Start immediately when page loads
33+ startScanner ( ) ;
2334</ script >
2435
2536< style >
You can’t perform that action at this time.
0 commit comments