[web-bluetooth] errorSecurityError: Origin is not allowed to access the service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options. https://goo.gl/HxfxSQ

brave2016 has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== errorSecurityError: Origin is not allowed to access the service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options. https://goo.gl/HxfxSQ ==
function search(){
 document.getElementById("demo").innerHTML="My First JavaScript";
 let options = {};
 let filters = [];
 let filterName = document.querySelector('#name').value;
  if (filterName) {
    filters.push({name: filterName});
  options.filters = filters;
  }else{
  options.acceptAllDevices = true;
  }
  
 navigator.bluetooth.requestDevice(options).then(device => {
   console.log('Got device:', device.name);
   console.log('id:', device.id);
   console.log('Connected:' + device.gatt.connected);
   console.log('Connected:' + device.gatt.connected);
   document.getElementById("demo").innerHTML="My First JavaScript"+device.name;
 return device.gatt.connect();
         
   }).then(server => {
    document.getElementById("service").innerHTML="trurservcice";
   
    return server.getPrimaryService('00000000-0000-1000-8000-00805f9b34fb');
   }).then(service => {
   
   return Promise.all([
   
               service.getCharacteristic('00000002-0000-1000-8000-00805f9b34fb'),
      
      service.getCharacteristic('00000003-0000-1000-8000-00805f9b34fb').then(read)
   
   ]);
 
             })
   
   .catch(error => {
   document.getElementById("demo").innerHTML="error"+error;
   });
 
}

function read(characteristic){
    return characteristic.startNotifications()
    .then(char => {
    characteristic.addEventListener('characteristicvaluechanged',
                                    onHeartRateChanged);
    });
}

function onHeartRateChanged(event) {
  let characteristic = event.target;
  console.log(parseHeartRate(characteristic.value));
  document.getElementById("data").innerHTML="D"+characteristic.value;
}

Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/370 using your GitHub account

Received on Monday, 17 July 2017 07:03:59 UTC