Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent PWA from opening links and Auth0 single sign in authentication in new Safari Window

I have an issue, I've created an angular PWA and my app uses auth0-lock as its authentication now my problem is.. when you click one of the single sign-in options like Google, for example, you get taken out of the PWA and into safari, Is there any way I can prevent this??

I have tried putting this code in my index.html

<!-- Prevent app from opening new safari page -->
<script type="text/javascript">
    (function(document,navigator,standalone) {
        // prevents links from apps from oppening in mobile safari
        // this javascript must be the first script in your <head>
        if ((standalone in navigator) && navigator[standalone]) {
            var curnode, location=document.location, stop=/^(a|html)$/i;
            document.addEventListener('click', function(e) {
                curnode=e.target;
                while (!(stop).test(curnode.nodeName)) {
                    curnode=curnode.parentNode;
                }
                // Condidions to do this only on links to your own app
                // if you want all links, use if('href' in curnode) instead.
                if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) {
                    e.preventDefault();
                    location.href = curnode.href;
                }
            },false);
        }
    })(document,window.navigator,'standalone');
</script>

but that doesn't seem to be working, I have seen some other javascript hacks that can prevent this and I have still yet to find one that works in my angular application?

Does anyone have any experience with this??

Thanks

like image 857
Smokey Dawson Avatar asked Jun 01 '18 02:06

Smokey Dawson


1 Answers

It's not particular to Angular but to PWA. Apple changed behaviour in iOS 11.3 following new PWA manifest rules.

The issue is known and Apple will be working on it.

Unfortunately, it means that there is not much to do in PWA for iOS 11.3…

like image 122
Buzut Avatar answered Oct 24 '22 12:10

Buzut