This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/cordova-plugin-inappbrowser.git


The following commit(s) were added to refs/heads/master by this push:
     new 6106897  fix(ios): set callbackId only on target=_blank, update readme 
(#1143)
6106897 is described below

commit 61068977da8e173a97754a0df64086460d3d5bda
Author: Manuel Beck <[email protected]>
AuthorDate: Wed May 6 17:26:55 2026 +0200

    fix(ios): set callbackId only on target=_blank, update readme (#1143)
    
    * fix(ios): set `callbackId` only on target=_blank
    
    - The `callbackId` would be overwritten, if the InAppBrowser is called with 
target=_system from a InAppBrowser event callback, like `beforeload`, to open 
links in an external browser. The documentation also states that the reference 
to the `InAppBrowser` window is set, when the target is set to `'_blank'` only.
    
    * doc(readme): Android specifics for target=_self and non-whitelisted URLs
    
    - On Android, non-whitelisted URLs also fall back to the `InAppBrowser` 
when the target is set to `'_self'`. On iOS not.
---
 README.md                   | 10 +++++++---
 src/ios/CDVWKInAppBrowser.m | 18 ++++++++++++------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index a19030d..e2fe4d3 100644
--- a/README.md
+++ b/README.md
@@ -92,13 +92,13 @@ instance, or the system browser.
 
     var ref = cordova.InAppBrowser.open(url, target, options);
 
-- __ref__: Reference to the `InAppBrowser` window when the target is set to 
`'_blank'`. _(InAppBrowser)_
+- __ref__: Reference to the `InAppBrowser` window when the target is set to 
`'_blank'`. _(InAppBrowser)_ On Android, non-whitelisted URLs also fall back to 
the `InAppBrowser` when the target is set to `'_self'`.
 
 - __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL 
contains Unicode characters.
 
 - __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`.
+    - `_self`: Opens in the Cordova WebView. On Android, non-whitelisted URLs 
fall back to the `InAppBrowser`. On iOS, the current implementation does not 
perform this fallback and navigation remains in the Cordova WebView (subject to 
`<allow-navigation>`).
     - `_blank`: Opens in the `InAppBrowser`.
     - `_system`: Opens in the system's web browser.
 
@@ -181,6 +181,8 @@ Since the introduction of iPadOS 13, iPads try to adapt 
their content mode / use
 
 The example above forces the user agent to contain `iPad`. The other option is 
to use the value `desktop` to turn the user agent to `Macintosh`.
 
+The current iOS implementation of `target='_self'` does not fall back to 
`InAppBrowser` for non-whitelisted URLs. If you need guaranteed `InAppBrowser` 
behavior on iOS, use `target='_blank'`.
+
 ### Browser Quirks
 
 - Plugin is implemented via iframe,
@@ -714,11 +716,13 @@ iab.open('https://whitelisted-url.com', 'random_string', 
'location=no'); // load
 
 ### Urls that are not white-listed
 
+Platform note: `_self` differs by platform for non-whitelisted URLs. On 
Android it falls back to `InAppBrowser`. On iOS it stays in the Cordova WebView 
and is controlled by `<allow-navigation>`.
+
 ```
 var iab = cordova.InAppBrowser;
 
 iab.open('https://url-that-fails-whitelist.com');                  // loads in 
the InAppBrowser
-iab.open('https://url-that-fails-whitelist.com', '_self');         // loads in 
the InAppBrowser
+iab.open('https://url-that-fails-whitelist.com', '_self');         // Android: 
loads in the InAppBrowser, iOS: handled by Cordova WebView rules
 iab.open('https://url-that-fails-whitelist.com', '_system');       // loads in 
the system browser
 iab.open('https://url-that-fails-whitelist.com', '_blank');        // loads in 
the InAppBrowser
 iab.open('https://url-that-fails-whitelist.com', 'random_string'); // loads in 
the InAppBrowser
diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m
index fb79d1b..129303f 100644
--- a/src/ios/CDVWKInAppBrowser.m
+++ b/src/ios/CDVWKInAppBrowser.m
@@ -78,26 +78,32 @@
 - (void)open:(CDVInvokedUrlCommand *)command
 {
     CDVPluginResult *pluginResult;
-
     NSString *url = [command argumentAtIndex:0];
     NSString *target = [command argumentAtIndex:1 
withDefault:kInAppBrowserTargetSelf];
     NSString *options = [command argumentAtIndex:2 withDefault:@"" 
andClass:[NSString class]];
 
-    self.callbackId = command.callbackId;
-
     if (url != nil) {
-        NSURL *baseUrl = [self.webViewEngine URL];
-        NSURL *absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] 
absoluteURL];
+        NSURL *absoluteUrl = [[NSURL URLWithString:url
+                                     relativeToURL:[self.webViewEngine URL]] 
absoluteURL];
 
         if ([self isSystemUrl:absoluteUrl]) {
             target = kInAppBrowserTargetSystem;
         }
 
+        // target=_self - Open in Cordova WebView
         if ([target isEqualToString:kInAppBrowserTargetSelf]) {
             [self openInCordovaWebView:absoluteUrl withOptions:options];
+            
+            // target=_system - Open external
         } else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
             [self openInSystem:absoluteUrl];
-        } else { // _blank or anything else
+            
+            // target=_blank or anything else, open in in-app browser
+        } else {
+            // Only set the command callback id here
+            // Don't set or overwrite it when target _system or _self is 
called, cause this will
+            // not invoke an in-app browser instance
+            self.callbackId = command.callbackId;
             [self openInInAppBrowser:absoluteUrl withOptions:options];
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to