-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[firebase_messaging]: getToken() does not work on Safari, works on Chrome and Firefox. 'Request contains an invalid argument' #13048
Comments
@andynewman10 Thank you for reporting this issue. I've tested the example app found here: https://github.com/firebase/flutterfire/tree/master/packages/firebase_messaging/firebase_messaging/example, and I found that after clicking on request permissions and refreshing the page, it works without issues. Can you try and see if the example app works for you, or if you still face the same issue? |
Your example does not work on my setup when using Safari. All tests done on macOS Ventura 13.6.7, Safari 17.5
Javascript console output (click to expand)
|
@TarekkMA how do you run the web page on Safari? Flutter for VS code cannot run or start a debug session on Safari, at least not directly. To test the page on Safari, I start a debug session on Chrome (with F5), which starts the development web server on, eg. http://localhost:45502. I then leave the page open in Chrome, and open the page separately with Safari. Note that no matter how I test the page with Safari (requesting permissions then refreshing the page, like you ; or using a desktop shortcut to validate permissions beforehand, which I prefer to do), I get the same error. |
The problem happens even if I change my locale to US english, system-wide. I tried with Firefox and Chrome and, again, there is no issue with these browsers. |
You can reproduce the issue with the example app by running the following command
Now test the page on Safari. Either just surf on the page then refresh it, or create a link on your desktop by dragging the URL from the browser address bar to the desktop. The Javascript console with display the following errors
Using Flutter 3.22.2, firebase_core 3.1.1, firebase_messaging 5.1.1. In the Javascript console, if I click on https://fcmregistrations.googleapis.com/v1/projects/flutterfire-e2e-tests/registrations I get: Request:
Response:
|
Full request headers:
I tried disabling CORS restrictions in Safari, didn't make any difference |
I see a similar issue has been reported here: |
Thank you for the update |
@TarekkMA Can I ask you what macOS version you are using? Are you by chance using macOS Sonoma? |
Yes, and this is my macos version: 14.5 (23F79) |
Thanks for your quick reply. @andreififiita, like me, is using macOS Ventura 13.6.x. I wonder if this detail plays a role in the problem we observe. We are both using Safari 17.4/17.5. |
@TarekkMA @andynewman10 That is correct, i am using macOS Ventura 13.6.7. |
@TarekkMA @andreififiita I suspect the problem might only affect Ventura. It would be a valuable piece of information for the firebase-js-sdk people to know if the problem is Ventura-related. Unfortunately I just have one Mac with Ventura, with no possibility to upgrade (MacBook A1708 from 2017). |
@andynewman10 did you ever resolve this issue? |
I managed to trigger request permission popup by requesting it manually, trigger it on a button. |
Is there an existing issue for this?
Which plugins are affected?
Messaging
Which platforms are affected?
Web
Description
Firebase Cloud Messaging does not work on Safari,
getToken()
raises an exception. Works fine with Chrome and Firefox.Reproducing the issue
You need a valid Firebase account and a vapidKey to replicate this issue with the instructions below.
Please carefully follow the steps described here to replicate the issue.
----Code preparation----
flutter create firetestapp --platforms web
. In theweb
folder, add an emptyfirebase-messaging-sw.js
file (I usually add a comment in this file to be on the safe side).pubspec.yaml
file, add the following dependenciesThe same issue can be seen with
firebase_core: ^2.32.0
andfirebase_messaging: ^14.9.4
.4. From your prompt do a
dart pub global activate flutterfire_cli
. For my tests, I usedfirebase-tools@13.8.3
5.
firebase login
. Log yourself in if necessary.6.
flutterfire configure
. Select your Firebase project, just select the 'web' target and let the program do its job.7. Modify the main.dart file this way:
Add this at the start of the file:
and change the
_incrementCounter()
function to look like this (do a copy/paste):----Running the code----
[firebase_messaging/permission_blocked] Messaging: The notification permission was not granted and blocked instead
.FirebaseMessaging.instance.requestPermission()
, which does returnAuthorizationStatus.granted
.getToken()
now raises the following exception:[firebase_messaging/token-subscribe-failed] Messaging: A problem occurred while subscribing the user to FCM. Request contains an invalid argument.
In the Safari Developer Tools, one can see that service workers are running (both flutter's and firebase's (firebase-messaging-sw.js))
Firebase Core version
3.1.1
Flutter Version
3.22.2
Relevant Log Output
See the exception text in the code above.
Flutter dependencies
Expand
Flutter dependencies
snippetAdditional context and comments
The piece of code given in this issue works fine with both Google Chrome and Mozilla Firefox. Only Safari has a problem.
The text was updated successfully, but these errors were encountered: