Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FBP web SecurityError in requestDevice() #1108

Open
1 task done
mgeilich opened this issue Jan 19, 2025 · 2 comments
Open
1 task done

FBP web SecurityError in requestDevice() #1108

mgeilich opened this issue Jan 19, 2025 · 2 comments
Labels
help Questions, help, observations, or possible bugs

Comments

@mgeilich
Copy link

Requirements

  • I've looked at the README 'Common Problems' section

Have you checked this problem on the example app?

No

FlutterBluePlus Version

1.34.5

Flutter Version

3.27.0

What OS?

macOS

OS Version

MacOS 15.2

Bluetooth Module

custom

What is your problem?

With FBP web, when I try to get services for a device, it fails with this:

DartError: FlutterBluePlusException | discoverServices | web-code: 0 | SecurityError: Origin is not allowed to access any service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options. https://goo.gl/HxfxSQ

I am running with flutter run -d chrome

I have tried to specify optionalServices in flutter_blue_plus_web.dart but either I don't have the syntax right or it isn't the right solution. Can you help?
options = RequestDeviceOptions(
filters: filters.toJS,
optionalServices:
js.JsArray.from([Guid.fromString('00006459-0000-1000-8000-00805F9B34FB'), Guid.fromString('6459')])
as JSArray);

Logs

HA: BluetoothDevice{remoteId: nJB1Hqfeohd6OwQ05FlxUg==, platformName: CHA-E0040258, services: null} is connected
DartError: FlutterBluePlusException | discoverServices | web-code: 0 | SecurityError: Origin is not allowed to access any service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options. https://goo.gl/HxfxSQ
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3  throw_
errors.dart:288
packages/flutter_blue_plus/src/bluetooth_device.dart 296:9                   <fn>
bluetooth_device.dart:296
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19          <fn>
async_patch.dart:610
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23          <fn>
async_patch.dart:634
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 581:31          <fn>
async_patch.dart:581
dart-sdk/lib/async/zone.dart 1676:54                                         runUnary
zone.dart:1676
dart-sdk/lib/async/future_impl.dart 204:18                                   handleValue
future_impl.dart:204
dart-sdk/lib/async/future_impl.dart 902:44                                   handleValueCallback
future_impl.dart:902
dart-sdk/lib/async/future_impl.dart 931:13                                   _propagateToListeners
future_impl.dart:931
dart-sdk/lib/async/future_impl.dart 707:5                                    [_completeWithValue]
future_impl.dart:707
dart-sdk/lib/async/future_impl.dart 1007:16                                  <fn>
future_impl.dart:1007
dart-sdk/lib/async/zone.dart 1676:54                                         runUnary
zone.dart:1676
dart-sdk/lib/async/future_impl.dart 204:18                                   handleValue
future_impl.dart:204
dart-sdk/lib/async/future_impl.dart 902:44                                   handleValueCallback
future_impl.dart:902
dart-sdk/lib/async/future_impl.dart 931:13                                   _propagateToListeners
future_impl.dart:931
dart-sdk/lib/async/future_impl.dart 707:5                                    [_completeWithValue]
future_impl.dart:707
dart-sdk/lib/async/future_impl.dart 777:7                                    callback
future_impl.dart:777
dart-sdk/lib/async/schedule_microtask.dart 40:11                             _microtaskLoop
schedule_microtask.dart:40
dart-sdk/lib/async/schedule_microtask.dart 49:5                              _startMicrotaskLoop
schedule_microtask.dart:49
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 186:7           <fn>
async_patch.dart:186
Done scanning for headsets
@mgeilich mgeilich added the help Questions, help, observations, or possible bugs label Jan 19, 2025
@ekuleshov
Copy link
Collaborator

@mgeilich first of all you need to use flutter_blue_plup: ^1.35.0 in your pubspec.yaml.
The flutter_blue_plus_web is an endorsed package and it will be automatically included.

The error you seeing "Origin is not allowed to access any service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options" is somewhat misleading in the context of Flutter/Dart. It is the web bluetooth error, which is basically telling you that you have to specify service UUIDs you want to connect to when doing the device scan.

So, you have to use the FlutterBluePlus.startScan(..., withServices: services) and specify your services there.

@mgeilich
Copy link
Author

@ekuleshov Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions, help, observations, or possible bugs
Projects
None yet
Development

No branches or pull requests

2 participants