[Fixed] Angular app with bluetooth device detector


I am building a web app (run on mobile browser, not a mobile app), the purpose is to be able to detect a bluetooth device nearby so user can clock in/out for their attendance.

I have a working code https://stackblitz.com/edit/bluetooth-3ibcww and has to run in https://bluetooth-3ibcww.stackblitz.io/ to avoid CROS error.
Is there a way to avoid the "prompt"? I need to simulate a flow where user hit "Register Attendance" button, backend will scan nearby bluetooth devices and recognize specific "ATTENDANCE_DETECTOR" bluetooth, to prove that the worker is physically nearby office/factory.
Here is the working codes

let options = {
  acceptAllDevices: true,
  optionalServices: ["battery_service"]

  .then(function(device) {
    console.log("Name: " + device.name);
    // Do something with the device.
  .catch(function(error) {
    console.log("Something went wrong. " + error);

i checked through the official doc https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth
it seems like there is only one available method requestDevice()


It is not possible to avoid the prompt. Requiring the user to select the device before the site can communicate with it is part of the security and privacy model for this API. If the site were allowed to scan for and detect devices without the user’s permission that could be used for any of a number of nefarious purposes such as secretly tracking the user’s location.

There is a draft specification for a Bluetooth scanning-specific API and prototype implementation available in Chromium if you pass the --enable-experimental-web-platform-features flag or enable it at chrome://flags/#enable-experimental-web-platform-features. As currently prototyped this API displays a prompt showing the user the kinds of devices the site could discover around them before granting the site access. This work is still in the development stage and there is no timeline for making this feature generally available.

Leave a Reply

(*) Required, Your email will not be published