Firebase-js-sdk: method "isMobileCordova()" and "fireauth.util.isAndroidOrIosCordovaScheme()" fail to detect a cordova environment causes ERROR auth/operation-not-supported-in-this-environment running cordova + iPad iOS 13.6

Created on 10 Aug 2020  路  7Comments  路  Source: firebase/firebase-js-sdk

[REQUIRED] Describe your environment

  • Operating System version: iOS 13.6
  • Browser version: Cordova running iPad iOS 13.6
  • Firebase SDK version: latest
  • Firebase Product: auth

[REQUIRED] Describe the problem

Because the UserAgent of iPad iOS 13.6 is "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
the method "isMobileCordova()" fail to detect a cordova environment

method "isMobileCordova()" at https://github.com/firebase/firebase-js-sdk/blob/master/packages/util/src/environment.ts#L42

Steps to reproduce:

run firebase-js-sdk on cordova with iPad iOS 13.6
try to use auth
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider); //Error

Error: This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.

Relevant Code:

method "isMobileCordova()" fail to detect a cordova environment
at https://github.com/firebase/firebase-js-sdk/blob/master/packages/util/src/environment.ts#L42

auth

Most helpful comment

Actually
<preference name="PreferredContentMode" value="mobile" />

Didn't work for me as navigator.userAgent still was:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

But isAndroidOrIosCordovaScheme has check only on /iphone|ipad|ipod|android/

fireauth.util.isAndroidOrIosCordovaScheme = function(opt_userAgent) {
  var ua = opt_userAgent || fireauth.util.getUserAgentString();
  return !!((fireauth.util.getCurrentScheme() === 'file:' ||
             fireauth.util.getCurrentScheme() === 'ionic:') &&
            ua.toLowerCase().match(/iphone|ipad|ipod|android/));
};

So current workaround use:

 <preference name="AppendUserAgent" value="ipad" />

cc: @hsubox76, @victorvhpg

_ps. Personally, as a future improvement, I'd consider passing environment(crodova,web) as a prop during initialization instead of such checks._

All 7 comments

Someone from the auth team will look into this soon, but isMobileCordova() isn't used by the current version of the auth library, which has its own (Closure) utilities. The Auth Cordova checking function should be here: https://github.com/firebase/firebase-js-sdk/blob/78cdb8b09eb1dceb2c247a5794137420fc55318f/packages/auth/src/utils.js#L567

We should also look into keeping isMobileCordova() current as well. Is this UserAgent string change recent?

Someone from the auth team will look into this soon, but isMobileCordova() isn't used by the current version of the auth library, which has its own (Closure) utilities. The Auth Cordova checking function should be here:

https://github.com/firebase/firebase-js-sdk/blob/78cdb8b09eb1dceb2c247a5794137420fc55318f/packages/auth/src/utils.js#L567

We should also look into keeping isMobileCordova() current as well. Is this UserAgent string change recent?

fireauth.util.isAndroidOrIosCordovaScheme = function(opt_userAgent) {
  var ua = opt_userAgent || fireauth.util.getUserAgentString();
  return !!((fireauth.util.getCurrentScheme() === 'file:' ||
             fireauth.util.getCurrentScheme() === 'ionic:') &&
            ua.toLowerCase().match(/iphone|ipad|ipod|android/));
};

@hsubox76
On iPad iOS 13.6 userAgent is: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
that code fail to detect cordova in iPad iOS 13.6

..... && ua.toLowerCase().match(/iphone|ipad|ipod|android/)
...

@hsubox76
The useragent default on iPad ios13 webview its like desktop.
iPadOS 13 defaults to using a desktop layout in webviews rather than a mobile layout. See:
https://developer.apple.com/videos/play/wwdc2019/203/

On cordova we can control this behaviour in your apps with the PreferredContentMode preference in config.xml.
I think its necessary to update the page
https://firebase.google.com/docs/auth/web/cordova
with that on iPad ios13 we need set
PreferredContentMode to "mobile" on config.xml.

<preference name="PreferredContentMode" value="mobile" />

Actually
<preference name="PreferredContentMode" value="mobile" />

Didn't work for me as navigator.userAgent still was:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

But isAndroidOrIosCordovaScheme has check only on /iphone|ipad|ipod|android/

fireauth.util.isAndroidOrIosCordovaScheme = function(opt_userAgent) {
  var ua = opt_userAgent || fireauth.util.getUserAgentString();
  return !!((fireauth.util.getCurrentScheme() === 'file:' ||
             fireauth.util.getCurrentScheme() === 'ionic:') &&
            ua.toLowerCase().match(/iphone|ipad|ipod|android/));
};

So current workaround use:

 <preference name="AppendUserAgent" value="ipad" />

cc: @hsubox76, @victorvhpg

_ps. Personally, as a future improvement, I'd consider passing environment(crodova,web) as a prop during initialization instead of such checks._

Same issue here on iPadOS / iOS 14.0.1 and @firebase/auth 0.14.9

Anything I can contribute to get this resolved?

Perhaps it's easier to test for Cordova or Capacitor presence?
Or couldn't you allow ionic:// and file:// without restricting to ios/android?

Actually it seems like the error you would get from fireauth.util.isAndroidOrIosCordovaScheme failing would be 'Cordova must run in an Android or iOS file scheme.' Is anyone seeing that?

The code causing the error in the issue ("Error: This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.") seems to be
https://github.com/firebase/firebase-js-sdk/blob/78cdb8b09eb1dceb2c247a5794137420fc55318f/packages/auth/src/utils.js#L1038

which, if it fails, leads to this case:
https://github.com/firebase/firebase-js-sdk/blob/78cdb8b09eb1dceb2c247a5794137420fc55318f/packages/auth/src/cordovahandler.js#L523

which is the reported error message.

I wonder if this case (it's Cordova but it's not iOS or Android) is a case we need to account for? Can that happen? Or if we're confident in our Android check, would it be safe to frame this conditional as

if (fireauth.util.isAndroid()) {
  ...
} else {
  // assume iOS
}

?

Was this page helpful?
0 / 5 - 0 ratings