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

Links with target _blank are not working on iOS inside inAppBrowser when wkwebview is enabled #390

Open
teroauralinna opened this issue Jan 3, 2019 · 14 comments

Comments

@teroauralinna
Copy link

teroauralinna commented Jan 3, 2019

Links with target _blank are not working on iOS when they are opened from the inAppBrowser and wkwebview is enabled. This is also an issue with a form element which has target _blank. Nothing happens when you tap link or submit form. Links without _blank are working correctly.

Tested with the master version 3.1.0-dev and setting usewkwebview=yes

Happens on various iPhones and simulator.

Here is the repo for minimal reproduction of the issue:
https://github.com/teroauralinna/cordova-iab-wkwebview

In the issue demo, click Open inAppBrowser and then Link with _blank doesn't work! => nothing happens

@brian-rose-sp
Copy link

I am also seeing this exact same thing on 3.1.0-dev. I tracked it down to the navigateTo method in CDVWKInAppBrowser. For whatever reason, when it attempts to acquire a lock by calling acquireLock in CDVUserAgentUtil, it is unable to obtain it and waits indefinitely.

I did modify the code locally to always make the request in navigateTo and it works. And after that, it appears to work randomly and then eventually asserts in the releaseLock method in CDVUserAgentUtil

@brian-rose-sp
Copy link

I am extremely new to Objective-C, Swift, Cordova, etc., so keep that in mind.

It appears as if the lock acquired by previous calls to CDVUserAgentUtil.acquireLock causes the global lock to be obtained and never released. When the InAppBrowser navigateTo is called, since _userAgentLockToken will always be 0 in this case, the gCurrentLockToken check in acquireLock will never be 0 and therefore, it will always create a wait and since releaseLock is never called (until the app exists), the pending requests will never obtain the lock.

@brian-rose-sp
Copy link

I figured this out on my side. I am posting here so it might help anyone who runs in to the same issue.

Cordova's CDVWKWebViewEngine checks to see if the view controller you are instantiating implements UINavigationDelegate. If it does, it uses that instead of the default implementation in CDVWKWebViewEngine.

Since I had implemented my own navigation delegate, the default's implementation of didFinishNavigation wasn't being called and that method is what releases the lock. Unfortunately, you have to know this if you want to implement the delegate yourself.

So, for now, maybe not the best solution, but I am just doing

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        // MUST release the lock that was obtained by the engine or else inAppBrowser won't be able to load it's page!
        // The CDVWkWebViewEngine does this for us if you use their WKNavigationDelegate, but since we are implementing
        // this interface here, Cordova knows to use our view controller as the delegate.  Therefore, we lose them
        // unlocking stuff for us, etc.  This isn't ideal and overriding the CDVWKWebViewEngine seems weird.  Possibly
        // go back to having this plugin's main class derive from CDVWKWebViewEngine, but that was causing other issues
        // and with my inexperience with Swift, Obj-C, and this whole stack, I am just going to release the lock here.
        CDVUserAgentUtil.releaseLock(userAgentLockToken);   
    } 

@mosabab
Copy link
Contributor

mosabab commented Feb 9, 2019

Hello,

This happened to me also, inappbrowser with usewkwebview =yes , will not open any links with <a href= target=_blank> (this mean for browser : to open the link in new tab) but for inappbroswer, it should open in the same window.)

I hope from the team to solve this issue.

@dpa99c
Copy link
Contributor

dpa99c commented Feb 27, 2019

This is a duplicate of #417 which is fixed by PR #418 (and #425)

@redoz94
Copy link

redoz94 commented Mar 25, 2020

This is a duplicate of #417 which is fixed by PR #418 (and #425)

Pls post the solution, so I can try and figure it out

@stealthmajor
Copy link

This issue still seems to be pending. I have similar issues. Even with a brand new ionic v1 app which comes with default wkwebview plugin and after I added the latest cordova inappbrowser plugin, the in app browser doesn't open. After I removed wkwebview plugin, the in app browser is working. I am stuck with this issue for the past week and cannot make this work and can't find any solutions as I did a lot of searching this past week. This is the closest thread where the same issue is discussed. Can someone please help ?

@rricamar
Copy link

rricamar commented May 11, 2020

This issue still seems to be pending. I have similar issues. Even with a brand new ionic v1 app which comes with default wkwebview plugin and after I added the latest cordova inappbrowser plugin, the in app browser doesn't open. After I removed wkwebview plugin, the in app browser is working. I am stuck with this issue for the past week and cannot make this work and can't find any solutions as I did a lot of searching this past week. This is the closest thread where the same issue is discussed. Can someone please help ?

Same here, _blank not working 😞

@arielnmagno
Copy link

Has this been fixed yet? :'(

@consciouscoder
Copy link

I'm having this same issue. _blank is not working. Can we get a fix please? Thank you!

@mosabab
Copy link
Contributor

mosabab commented May 29, 2020

@consciouscoder @arielnmagno

Please use the latest version of this plugin or the master version.

As the documentation for this plugin:

target: The target in which to load the URL, an optional parameter that defaults to _self. (String)

_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.

So,

  • If you want to open the link in inapapbrowser plugin you should use _blank.

Example:
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');

  • if you want to open the link in mobile device web browsers you should use _system

Example:
var ref = cordova.InAppBrowser.open('http://apache.org', '_system', 'location=yes');

@mosabab
Copy link
Contributor

mosabab commented Jun 6, 2020

@consciouscoder @arielnmagno

Please use the latest version of this plugin or the master version.

As the documentation for this plugin:

target: The target in which to load the URL, an optional parameter that defaults to _self. (String)

_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.

So,

  • If you want to open the link in inapapbrowser plugin you should use _blank.

Example:
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');

  • if you want to open the link in mobile device web browsers you should use _system

Example:
var ref = cordova.InAppBrowser.open('http://apache.org', '_system', 'location=yes');

Additional inofrmation:

(NOTE: wkwebview has been integrated to the plugin it self, there is no need to use 'wkwebview=yes' any more.)

So if you used : wkwebview=yes in the options, please remove it, and also there is no need for the cordova-plugin-wkwebview-engine because it is already integrated to the cordova-ios.

Regards

@consciouscoder
Copy link

_blank: Opens in the InAppBrowser.

I couldn't get inAppBrowser with _blank parameter to trigger the loadstart event nor perform a close method on a redirect from an Oauth call while in WKWebView. This was old code that worked in UIWebView but was broken when I updated the Ionic app to WKWebView. I decided to swtich to SafariViewController (https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller) and all is working great. Thanks for the help @mosabab

@juanmagua

This comment was marked as off-topic.

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

No branches or pull requests