question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash with custom-url-scheme on android

See original GitHub issue

I am trying to replace InAppBrowser with SafariViewController in oAuth flow involving a web server. See #34.

The redirect_uri on the web server (which is whitelisted with the oAuth provider) returns:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Security-Policy" content="default-src 'none';script-src 'unsafe-inline';">
</head>
<body>
    <script>window.location.assign('com.example.app://token' + window.location.hash);</script>
</body>
</html>

then the handleOpenURL event handler parses the oAuth token in the hash.

This works perfectly in iOS but in android SafariViewController crashes on the above page before hitting handleOpenURL.

I know the custom url scheme is properly configured because I can hit handleOpenUrl from a link in a page opened in Chrome.

if I replace:

<script>window.location.assign('com.example.app://token' + window.location.hash);</script>

with

<script>window.location.assign('http://www.google.com');</script>

the redirection works just fine so SafariViewController simply does not like ‘com.example.app://’ on Android only, not iOS.

Any suggestions to have SafariViewController (Chrome Tabs) accept a custom scheme made with https://github.com/EddyVerbruggen/Custom-URL-scheme on Android ?

Project can be found at https://github.com/kidoju/Kidoju-Mobile.

I am using:

  • Phonegap 6.3.0
  • Android Platform 5.2.1
  • Latest versions of all plugins (latest versions on Phonegap build as of today)

I am testing on a Nexus 7 with Android 5.1.1 and Chrome 54.0.2840.85.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jlchereaucommented, Dec 20, 2016

Thank you. You can easily reproduce the Chrome custom tabs “crashing” and the 10sec gap during which the splashscreen replaces the webview before hitting handleOpenURL by:

  1. Configuring a phonegap application with:
  2. Binding the click event of a button to
window.SafariViewController.show({  url: 'http://<your ip:port>/<your path>/scheme.html' });

where scheme.html is:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1><a href="com.example.app://token/#auth_token=ttttttttttt&state=ssssssss">Authenticate</a></h1>
</body>
</html>

Then just click the button to open Chrome custom tabs and click the Authenticate link.

1reaction
yakirncommented, Dec 5, 2016

That’s because in iOS the SafariViewController run as part of the application. While in android it is a different Activity (like a process) that is activated by your Cordova activity. What I’m saying is that it’s completely different code that runs on a completely different framework, so what is and isn’t working on iOS is not an indication to anything IMO. I hope I’ll have time to take a better look over the weekend. If you can find a working example of authentication using Chrome custom tabs, it might speed things up. Sorry I can’t help you more, and good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fall back to marketplace when Android custom URL ...
The key, it turns out, is the document.webkitHidden property. When you set window.location to a custom URL scheme and it opens, the browser ......
Read more >
Android URL scheme error when opening play store link
I've read some online forums and to me it looks like a fix is available by using webview with an intent instead of...
Read more >
Defining a custom URL scheme for your app - Apple Developer
Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch...
Read more >
Create Deep Links to App Content - Android Developers
To allow users to enter your app from links, you must add intent filters for the relevant activities in your app manifest. These...
Read more >
URL Scheme Intro for App Developers - Contrast Help
Creating URL Schemes: At the simplest level, a custom URL scheme allows users to open your app from other apps. But the true...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found