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

auth-compat module incorrectly detects Capacitor/Cordova environment on iPad #8755

Open
dpa99c opened this issue Feb 4, 2025 · 2 comments · May be fixed by #8756
Open

auth-compat module incorrectly detects Capacitor/Cordova environment on iPad #8755

dpa99c opened this issue Feb 4, 2025 · 2 comments · May be fixed by #8756

Comments

@dpa99c
Copy link

dpa99c commented Feb 4, 2025

Operating System

iPadOS 17.6.1

Environment (if applicable)

Cordova/Capacitor app running in WKWebview on iPadOS

Firebase SDK Version

11.2.0

Firebase SDK Product(s)

Auth

Project Tooling

Cordova app with webpack

Detailed Problem Description

The auth-compat module relies on matching the URL scheme and user agent string to detect whether it is running in a Cordova/Capacitor Webview in _isAndroidOrIosCordovaScheme.

However, since iPadOS 13 (circa 2019), Safari (and its WKWebView implementation) began identifying itself with a user agent string similar to that of macOS to provide a desktop-like browsing experience. This change means that the user agent string no longer contains iPad and instead resembles that of a Mac.
For example the user agent string of my iPad Simulator is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148.

This means the current detection fails to correctly detect that it is running in a Cordova/Capacitor Webview when running on an iPad, so assumes it's a desktop browser environment.
Therefore when the auth-compat module is imported, this leads to a run-time error:

Image

Steps and code to reproduce issue

  • On macOS with ionic environment for iOS development for Cordova:
  • Run in Terminal:
    • ionic start firebase-test blank --type=angular --cordova && cd firebase-test
    • npm install -g @angular/cli
    • ng add @ionic/cordova-builders
    • ionic cordova platform add ios
  • Edit src/main.ts and add:
window.onerror = function (message) {
  alert(message);
}
  • Run in Terminal:
    • ionic build
    • cordova platform prepare ios
  • Open platforms/ios/firebase-test.xcworkspace in Xcode
  • In Xcode, select a connected physical iPad or an iPad Simulator and then select "Run"
  • Observe that app launches without errors

Then add the Firebase SDK:

  • Run in Terminal: npm i firebase
  • Edit src/main.ts and add:
import firebase from '@firebase/app-compat';
import '@firebase/auth-compat';

const config = {
  // your project config
};
firebase.initializeApp(config)
console.log(firebase.auth().currentUser);
  • Run in Terminal:
    • ionic build
    • ionic cordova prepare ios
  • In Xcode, select a connected physical iPad or an iPad Simulator and then select "Run"
  • Observe than an error dialog appears
  • Inspect Webview with Safari Devtools and observer errors are due to Firebase SDK
@dpa99c dpa99c added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Feb 4, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: auth needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Feb 4, 2025
@jbalidiong
Copy link
Contributor

Hi @dpa99c, thank you for bringing this to our attention. I was able to replicate the issue. I'll take a closer look and see what we can do or loop in someone who has more context. I'll update this thread as soon as I have more details or information to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants