W3C home > Mailing lists > Public > public-web-bluetooth-log@w3.org > July 2017

Re: [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

From: François Beaufort via GitHub <sysbot+gh@w3.org>
Date: Wed, 19 Jul 2017 07:37:28 +0000
To: public-web-bluetooth-log@w3.org
Message-ID: <issue_comment.created-316299073-1500449846-sysbot+gh@w3.org>
You had a typo in `optionalServices`. See below:

```diff
function search() {
    document.getElementById("demo").innerHTML = "My First JavaScript";
    let options = {
-        optionalServices: ['00000003-0000-1000-8000-00805f9b34fb']
+        optionalServices: ['00000000-0000-1000-8000-00805f9b34fb']
    };
    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 => {
        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;
    });
}
```

-- 
GitHub Notification of comment by beaufortfrancois
Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/370#issuecomment-316299073 using your GitHub account
Received on Wednesday, 19 July 2017 07:37:34 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 19 July 2017 07:37:34 UTC