Custom-URL-scheme icon indicating copy to clipboard operation
Custom-URL-scheme copied to clipboard

App not launching from Chrome browser - Navigation is blocked

Open stalin opened this issue 9 years ago • 36 comments

When I try to open my Android app from mobile Chrome browser, it is not launching the app. Also, I got the following error message in the web console. Navigation is blocked: mycoolapp://

But, this works like charm in mobile Firefox browser. Any idea how to get it resolved?

stalin avatar Feb 27 '16 12:02 stalin

That's when clicking a link?

EddyVerbruggen avatar Feb 27 '16 15:02 EddyVerbruggen

No.. It is when I try to open the app using javascript on page load of a web page.

stalin avatar Feb 28 '16 13:02 stalin

Same issue when using a plain old link? Also, which Android version is this?

EddyVerbruggen avatar Feb 28 '16 14:02 EddyVerbruggen

<script> $(document).ready(function() { window.location="mycoolapp://"; }) </script> The above is the code that I'm using for opening up the native app from my web app. it was working fine previously.

Cordova CLI: 5.4.1 ionic platform android - 4.1.1 Android version - 4.4

stalin avatar Mar 01 '16 03:03 stalin

Same issue here. Seems that chrome on android now blocks opening other url schemes on page load :-1:

klickagent avatar Mar 12 '16 14:03 klickagent

Having same issue here... I send a return url to my paymentprovider, they return my url in coolapp:// format, but it says ERR_UNKNOWN_URL_SCHEME ... anyone have an idea? Weird thing is, that it's working on firefox.. but samsung standard browser and chrome won't work..

Thanks!!

oudj001 avatar Apr 08 '16 15:04 oudj001

Same issue here, Chrome locked the url...

Nico-Nico-FR avatar May 23 '16 10:05 Nico-Nico-FR

Instead of launching it as a custom-protocol. Try launching it as an Intent instead. This seem to be the main way to go on Android. E.g :

intent://#Intent;package=your_package_name;scheme=your_custom_url_schema;end;

Caine72 avatar Jun 03 '16 12:06 Caine72

any solution ?

flastowizka avatar Jun 09 '16 03:06 flastowizka

@Caine72 launching it as an intent it works only on Browser for me.

On Chrome still does not work.

Anyone else on this one?

@EddyVerbruggen

ghost avatar Jul 14 '16 13:07 ghost

For me, if you hide Chrome (e.g. press the home button), re-open chrome, and try the link again, the link works successfully. However, I always get the "Navigation is blocked" error when the page first loads. It's the weirdest thing...

(Edit: same for trying to access using an intent:// URI wit the scheme set)

blakek avatar Feb 13 '17 21:02 blakek

Actually, I just solved my issue. I was trying to redirect the user on page load. Apparently Chrome blocks all requests to another URI scheme without the user initiating it. I added a button on my landing page and it works now!! 🎉

blakek avatar Feb 13 '17 21:02 blakek

What would be the recommended way of launching an Android app from a redirect? For example, in Oauth2 flows, the Provider will do a browser redirect after authenticating. The goal would be to use a redirect to open the app. This would be similar to opening the App directly from the browser address bar. Any thoughts?

PaulMazzuca avatar Feb 16 '17 23:02 PaulMazzuca

This navigation block was added to Chrome recently (https://bugs.chromium.org/p/chromium/issues/detail?id=459156). It seems like the world is moving towards native-app OAuth flows (https://tools.ietf.org/html/draft-ietf-oauth-native-apps-10). Google has phased out web-based OAuth flows (https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html)

The only workaround is to use as a redirect URL the back-end, which can then issue the custom URL scheme (http://stackoverflow.com/questions/41524087/navigation-is-blocked-when-redirecting-from-chrome-custom-tab-to-android-app). I tried doing something similar on the front-end but you can only avoid the navigation block if it's a link instead of setting window.location:

<html>
<head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
  <script type="text/javascript">

    $(document).ready(function() {
function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
  var token = getUrlParameter("oauth_token");
  var verifier = getUrlParameter("oauth_verifier");

  $('#oauth').attr('href', "oauth://cprest/?oauth_token=" + token + "&oauth_verifier=" + verifier);
});
</script>
</head>
<a id="oauth" href="">Link</a>
</html>

rogerhu avatar May 09 '17 07:05 rogerhu

Try this code:

   var redirect = function (location) {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('src', location);
        iframe.setAttribute('width', '1px');
        iframe.setAttribute('height', '1px');
        iframe.setAttribute('position', 'absolute');
        iframe.setAttribute('top', '0');
        iframe.setAttribute('left', '0');
        document.documentElement.appendChild(iframe);
        iframe.parentNode.removeChild(iframe);
        iframe = null;
    };
 redirect(URL_HERE);

##Edited It gets blocked too. Sorry guys

muhammadfaizan avatar Apr 25 '18 12:04 muhammadfaizan

^This doesn't work in Android's Chrome browser.

wbrickner avatar May 14 '18 06:05 wbrickner

@wbrickner yeah it stopped working for me as well, but i had luck for having it work.

muhammadfaizan avatar May 14 '18 07:05 muhammadfaizan

What I ended up doing is attempting to detect the platform. If it's Andoid, show a button. The button has a listener which will redirect to the native schema url (e.g. "fb:// ..."), and then 100ms after that it will change the location to the mobile site (e.g. "https://facebook.com/ ..."). On iOS you do the same but don't wait for a button click.

wbrickner avatar May 14 '18 08:05 wbrickner

@wbrickner that certainly does work most of the time.. :+1:
But still we can get blocked

muhammadfaizan avatar May 14 '18 10:05 muhammadfaizan

Where in that process can you be blocked? This is a critical piece of infrastructure for my company. Please help me understand.

wbrickner avatar May 15 '18 21:05 wbrickner

if your button redirects upon user interaction then its fine, but if you redirect it by clicking the button from your javascript then it might get blocked

muhammadfaizan avatar May 17 '18 07:05 muhammadfaizan

@wbrickner if the redirect failure triggers a warning or a blocking modal by the browser then the timeout-based redirect could possibly not happen. If possible I think the server-side '302' redirect to the custom uri seems like the best option if you arent doing universal links or whatever is the current fragmented state of native deep linking world.

temitope avatar Dec 13 '18 20:12 temitope

A little trick to achieve that:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>My Cool App</title>
</head>
<body>
    <div id="redirect-div" onclick="navigate()">
        <h1>Opening My Cool App...</h1>
    </div>
</body>
<script type="text/javascript">
    setTimeout(() => {
        var div = document.getElementById('redirect-div');
        div.click();
    }, 1000);
    function navigate() {
        var url ="myCoolApp://mycooldomain.com";
        window.location = url;
    }
</script>
</html>

:)

Abdulrahmanh995 avatar Jul 27 '19 23:07 Abdulrahmanh995

This navigation block was added to Chrome recently (https://bugs.chromium.org/p/chromium/issues/detail?id=459156). It seems like the world is moving towards native-app OAuth flows (https://tools.ietf.org/html/draft-ietf-oauth-native-apps-10). Google has phased out web-based OAuth flows (https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html)

The only workaround is to use as a redirect URL the back-end, which can then issue the custom URL scheme (http://stackoverflow.com/questions/41524087/navigation-is-blocked-when-redirecting-from-chrome-custom-tab-to-android-app). I tried doing something similar on the front-end but you can only avoid the navigation block if it's a link instead of setting window.location:

<html>
<head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
  <script type="text/javascript">

    $(document).ready(function() {
function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
  var token = getUrlParameter("oauth_token");
  var verifier = getUrlParameter("oauth_verifier");

  $('#oauth').attr('href', "oauth://cprest/?oauth_token=" + token + "&oauth_verifier=" + verifier);
});
</script>
</head>
<a id="oauth" href="">Link</a>
</html>

How is this different from asking for user consent?? Is there any other way to launch app from deeplink without asking for user consent and launch the app as soon as my page gets launch??

sagg155 avatar Jan 04 '20 21:01 sagg155

Bump... Does anyone know if this issue has been resolved?

bennyhawk avatar May 15 '20 10:05 bennyhawk

We are also facing the same issue while opening the ionic app deeplink from the web browser .

Please let us know any solution for this.

VivithaAlamur avatar May 19 '20 13:05 VivithaAlamur

Read this article: https://developer.android.com/training/app-links/deep-linking

Setting up an http scheme did the trick for me. You can still also keep mycoolapp:// for button clicks.

sjoerdloeve avatar Jun 29 '20 14:06 sjoerdloeve

I have also encountered this issue now in Chrome android and Edge android browsers. It is working fine in Mozilla android and Safari iOS. Do you all have any other suggestions? I would really like to redirect the page on load instead of on button click. Thank you!

lorimay21 avatar Sep 30 '20 02:09 lorimay21

Read this article: https://developer.android.com/training/app-links/deep-linking

Setting up an http scheme did the trick for me. You can still also keep mycoolapp:// for button clicks. @sjoerdloeve Do you mean that you find a way to programatically call http(s) scheme deep link? How? My understanding is, that new(er) browsers (at least chrome) blocks "non-user-initiated" navigation links - that is a security feature. So, Deep link to both custom/http scheme works for me from ahref and button. Because it is a user action who initiated the navigation. But I have no way to call it programatically.

So, anybody know how to push data (attr=value) from webpage to application on target device? Anyhow? Thank you.

`

`

JV-TMCZ avatar Mar 09 '21 11:03 JV-TMCZ

@JV-TMCZ Yes, it's possible to click on a HTTPS link that directly opens the app if you have it installed. I'm using this plugin for the custom URL scheme and the universal links plugin for the HTTP(S) linking.

Check out this plugin and the documentation to set it up: https://github.com/eldadfux/cordova-plugin-universal-links

For iOS I use location.href on the HTML page to automatic trigger a confirm box to the user that ask if you would like to open the app.

sjoerdloeve avatar Mar 09 '21 14:03 sjoerdloeve