| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script> | 2 <script> |
| 3 window.onmessage = messageEvent => { | 3 window.onmessage = messageEvent => { |
| 4 // For requestDevice to work, 'Go' should be sent while |
| 5 // handling a user gesture. |
| 4 if (messageEvent.data === 'Go') { | 6 if (messageEvent.data === 'Go') { |
| 5 navigator.bluetooth.requestDevice({ | 7 navigator.bluetooth.requestDevice({ |
| 6 filters: [{services: ['generic_access']}] | 8 filters: [{services: ['generic_access']}] |
| 7 }).then(device => { | 9 }).then(device => { |
| 8 if (device.constructor.name === "BluetoothDevice") { | 10 if (device.constructor.name === "BluetoothDevice") { |
| 9 parent.postMessage('Success', '*'); | 11 parent.postMessage('Success', '*'); |
| 10 } else { | 12 } else { |
| 11 parent.postMessage('FAIL: requestDevice in iframe returned ' + device,
'*'); | 13 parent.postMessage('FAIL: requestDevice in iframe returned ' + device,
'*'); |
| 12 } | 14 } |
| 13 }).catch(err => { | 15 }).catch(err => { |
| 14 console.error(err); | 16 parent.postMessage(err.name + ': ' + err.message, '*'); |
| 15 parent.postMessage('FAIL: ' + err, '*'); | |
| 16 }); | 17 }); |
| 17 } | 18 } |
| 18 }; | 19 }; |
| 19 parent.postMessage("Ready", "*"); | 20 parent.postMessage("Ready", "*"); |
| 20 </script> | 21 </script> |
| OLD | NEW |