Bluetooth auto-reconnect: skip the pairing dialog | Ride Cave
All posts

Bluetooth auto-reconnect: skip the pairing dialog

How Ride Cave automatically reconnects your trainer, heart rate monitor, and power meter on page load.

Every time you open a cycling app in your browser, you normally have to click through the Bluetooth pairing dialog for each device. Select your trainer, wait for the list to populate, find the right device, click pair. Repeat for your heart rate monitor. Repeat again for your power meter. It gets tedious.

Ride Cave now remembers your devices and automatically reconnects them when you return. Open the app, and your trainer, heart rate monitor, and power meter connect silently in the background. No dialogs, no clicking, no waiting.

How it works

Web Bluetooth has a feature called getDevices() that returns previously-paired Bluetooth devices. Unlike the normal pairing flow, this API does not require user interaction. If the browser has permission from a previous pairing session, it can reconnect silently.

When you first connect a device in Ride Cave, we save its identifier to your browser's local storage. On subsequent visits, we check if that device is still in your browser's permitted devices list. If it is, we attempt to reconnect automatically.

The reconnection happens sequentially: trainer first, then heart rate monitor, then power meter. Each device gets a few seconds to respond before we move on to the next. This prevents Bluetooth conflicts that can occur when connecting multiple devices simultaneously.

The quirks of Web Bluetooth

Web Bluetooth is powerful but has some rough edges. The getDevices() API is relatively new and Chrome has been gradually rolling it out. On some systems, this feature is not enabled by default, even in recent Chrome versions.

If auto-reconnect is not working for you, you may need to enable a Chrome flag. Go to chrome://flags in your address bar, search for "web bluetooth", and enable the flag called "Web Bluetooth new permissions backend". Restart Chrome after making this change.

Even with this flag enabled, there is another requirement. Web Bluetooth needs to verify that your device is actually nearby before connecting. This happens through a process called advertisement watching. The browser listens for your device's Bluetooth advertisements, and only then allows the connection to proceed. This prevents the browser from trying to connect to devices that are turned off or out of range.

In practice, this means your device needs to be powered on and broadcasting before auto-connect will succeed. If your trainer is still spinning up when the page loads, you might see a brief "connecting" status before the connection completes.

When auto-connect runs

Auto-connect attempts run once when you load the app. The trainer attempts to connect after 200 milliseconds, the heart rate monitor after 500 milliseconds, and the power meter after 1 second. These delays prevent conflicts and give each device time to establish its connection.

If you manually connect a device before auto-connect fires, the automatic attempt is cancelled. Manual connections always take priority. This prevents strange behavior if you open the Bluetooth dialog while auto-connect is still trying.

Similarly, if you explicitly disconnect a device using the disconnect button, Ride Cave removes it from the saved devices list. This prevents unwanted reconnection on future visits. If you want to use a different trainer next time, just disconnect the old one and pair the new one.

Browser support

Auto-reconnect requires Chrome or Edge on desktop. Safari and Firefox do not support Web Bluetooth at all. On mobile, Chrome for Android supports Web Bluetooth, but iOS browsers are blocked by Apple's restrictions.

If your browser does not support the getDevices() API, auto-connect simply does not run. You will not see any errors, just the normal manual pairing flow when you click connect.

Troubleshooting

If auto-reconnect is not working, check these things in order:

First, make sure you are using Chrome or Edge. Other browsers do not support the required APIs.

Second, try enabling the Chrome flag. Go to chrome://flags, search for "web bluetooth", enable "Web Bluetooth new permissions backend", and restart Chrome.

Third, ensure your devices are powered on before loading the page. The advertisement watching step requires your devices to be broadcasting.

Fourth, check that you have previously paired the device. Auto-reconnect only works with devices you have connected at least once through the normal pairing dialog.

Finally, if you are on localhost during development and have the trainer simulator enabled, auto-connect is intentionally disabled to avoid conflicts with the simulated trainer.

Privacy and data

Device information is stored only in your browser's local storage. We save the device ID, name, device type, and last connection time. This data never leaves your browser and is not sent to any server.

If you clear your browser data or use incognito mode, saved devices are cleared and you will need to pair again through the normal dialog. You can also manually clear saved devices by disconnecting each one using the disconnect button in the app.

Ben Snyder
Founder of Ride Cave

Ready to try Ride Cave?

Ride Cave is free, runs in your browser, and requires no account to start.

Start Riding