firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.74k stars 3.98k forks source link

🐛 [firebase_dynamic_link] Dynamic link broke Safari on IOS when link contains unicode #11122

Closed nerder closed 10 months ago

nerder commented 1 year ago

Bug report

Describe the bug As in the title, when the link contains a unicode character such as ó the link will break Safari and not open correctly.

Steps to reproduce

Steps to reproduce the behavior:

  1. Open this link in the IOS Simulator https://arya.page.link/qV5g
  2. See the error message in Safari: Safari cannot open the page because the address is invalid

Expected behavior

To open the app correctly and fire the flutter integration as usual.

Sample project

This is not needed as I'm pretty confident that you will be able to reproduce this in the example app.


Additional context

You can try with a valid link such as this one: https://arya.page.link/6XZ5 and you can confirm that is indeed working as expected.

Also, this is the code used for generating the link in our backend:

const getParameters = (gymId: string) => {
  return {
    dynamicLinkInfo: {
      domainUriPrefix: `https://${process.env.DYNAMIC_LINK_DOMAIN}`,
      link: `https://www.getstriveapp.com/register/${gymId}`, //gmyId can contain unicode
      androidInfo: {
        androidPackageName: process.env.APP_UNIQUE_IDENTIFIER,
      },
      iosInfo: {
        iosBundleId: process.env.APP_UNIQUE_IDENTIFIER,
        iosAppStoreId: process.env.APPLE_STORE_ID,
      },
      navigationInfo: {
        enableForcedRedirect: true,
      },
    },
    suffix: {
      option: 'SHORT',
    },
  };
};

const generateReferralUrl = async (gymId: string) => {
  const response = await fetch(
    `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${process.env.WEB_FIREBASE_API_KEY}`,
    {
      method: 'POST',
      headers: {
        'content-type': 'application/json',
      },
      body: JSON.stringify(getParameters(gymId)),
    },
  );

  const jsonResponse = await response.json();

  const referralUrl = jsonResponse.shortLink;
  console.info(`generated referral link [${referralUrl}] for gym [${gymId}]`);

  return referralUrl;
};

Notes

I'm not sure if this is actually the right place to report this as it might as well be an issue with Safari since on Android the dynamic link works fine for the most part.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` PASTE OUTPUT INSIDE HERE ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.10.4, on macOS 13.3.1 22E772610a darwin-arm64, locale en-IT) • Flutter version 3.10.4 on channel stable at /Users/nerder/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 682aa387cf (7 days ago), 2023-06-05 18:04:56 -0500 • Engine revision 2a3401c9bb • Dart version 3.0.3 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/nerder/Library/Android/sdk • Platform android-33, build-tools 33.0.0 • Java binary at: /Users/nerder/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.12.1 [✓] Android Studio (version 2022.2) • Android Studio at /Users/nerder/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] Android Studio (version 2022.2) • Android Studio at /Users/nerder/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] IntelliJ IDEA Ultimate Edition (version 2023.1.2) • IntelliJ at /Users/nerder/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app • Flutter plugin version 74.0.4 • Dart plugin version 231.9065 [✓] IntelliJ IDEA Ultimate Edition (version 2023.1.2) • IntelliJ at /Users/nerder/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9011.34/IntelliJ IDEA.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] IntelliJ IDEA Ultimate Edition (version 2023.1.1) • IntelliJ at /Users/nerder/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.8770.65/IntelliJ IDEA.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] Connected device (3 available) • SM G975F (mobile) • R58M67B0S3Y • android-arm64 • Android 12 (API 31) • iPhone 14 Pro Max (mobile) • FB142510-43C2-45EC-BFF4-150B6E17F611 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3.1 22E772610a darwin-arm64 [✓] Network resources • All expected network resources are available. • No issues found! ```

darshankawar commented 1 year ago

Thanks for the report @nerder I accessed the link on iOS simulator in which I get the said behavior, but accessing it on physical device took me properly to app store, so that probably indicates it is not a plugin issue but could be specific to simulators as they don't have AppStore app and the link must be trying to find one and hence the error as address is invalid.

See if it helps to answer / resolve your issue.

nerder commented 1 year ago

Hey @darshankawar thank you for your fast reply, the problem is that when I have the app installed it should open it, not try to open the App Store.

can send you a quick video when the first link correctly opens the app in the simulator and the other return that error.

The expected behavior should be to open both links in the app to be handled properly.

nerder commented 1 year ago

Actually, after some extensive testing, it seems like the link doesn't even trigger the flutter code to be executed as it fails directly in the native code and spawns this error in the console:

https://github.com/firebase/flutterfire/blob/52d920a5ed7e06cbbf9105a20eefc56824475f27/packages/firebase_dynamic_links/firebase_dynamic_links/ios/Classes/FLTFirebaseDynamicLinksPlugin.m#L311

I'm not sure how to debug this further as i'm not proficient with Objective-C, I confirmed with the debugger tho that the code correctly end up in that branch (which probably should return an error instead of simply logging)

Here are the 2 links when expanded:

  1. https://arya.page.link/?link=https://www.getstriveapp.com/register/new_test&apn=com.arya.checkin.dev&isi=1471462737&ibi=com.arya.checkin.dev&efr=1
  2. https://arya.page.link/?link=https://www.getstriveapp.com/register/matar%C3%B3_jiujitsu&apn=com.arya.checkin.dev&isi=1471462737&ibi=com.arya.checkin.dev&efr=1

They are configured exactly in the same way the only differences are those special characters encoded in browser code that I suspect are breaking something.

darshankawar commented 1 year ago

Thanks for the update and digging deep. Can you take a look at this and see if using it in your scenario, still gives you same behavior or not ?

nerder commented 1 year ago

Hey @darshankawar I'm not sure I understand 100% what you want me to do here, can you please elaborate in this context?

darshankawar commented 1 year ago

Sorry if it wasn't clear earlier, but I wanted to see if you follow the steps mentioned in that link with respect to your app, run in release mode, generate the dynamic link to see if the same issue persists or not.

google-oss-bot commented 1 year ago

Hey @nerder. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

nerder commented 1 year ago

Up. I'll be providing more information between today and tomorrow. I was quite busy with a big release for my app.

nerder commented 1 year ago

hey @darshankawar, I don't have a real IOS device handy to do that test. But I'm pretty positive this is happening because it's happening with our app in production.

darshankawar commented 1 year ago

Thanks for the update. Can you take a look at this and see if it helps in your case ?

nerder commented 1 year ago

Hey @darshankawar no, this is not the case. It will only happen for links that contain Unicode, and it redirects to the store correctly when the app is not installed while in case the app is already installed it opens correctly, but the information persisted inside is not retrieved correctly.

If you have an iPhone handy is quite simple to reproduce also in production:

EDIT: I've actually had the chance to get my end on an actual real iPhone and the issue is indeed the same as in the simulator as I've explained here: https://github.com/firebase/flutterfire/issues/11122#issuecomment-1589237347

EDIT 2: You can also see a video with breakpoints on a Real iPhone Device here: https://www.loom.com/share/97d957c5a6b2480ab52e5b26a6e05b8f

This is a legit bug.

darshankawar commented 1 year ago

Thanks for the update. I do see the same behavior as reported using the links provided. I think there was already an issue or I read something about having unicode in dynamic links but can't seem to find any reference of it.

/cc @russellwheatley

nerder commented 1 year ago

There is an ETA for this?

nerder commented 1 year ago

Ping, any update?

russellwheatley commented 10 months ago

Hi folks, we'd like to inform you that the Firebase Dynamic Links service will be shutdown on August 25, 2025. In the meantime, only critical or security issues will be fixed in the SDK.

More at firebase.google.com/support/dynamic-links-faq