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

Bugfix FXIOS-7871 [v125] Opening a link in external app leaves a "loading" about:blank page behind #19288

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ extension BrowserViewController: WKUIDelegate {
screenshotHelper.takeScreenshot(currentTab)
}

if navigationAction.canOpenExternalApp, let url = navigationAction.request.url {
UIApplication.shared.open(url)
return nil
}
Comment on lines +36 to +39
Copy link
Collaborator

@mattreaganmozilla mattreaganmozilla Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically a similar fix to what was implemented for whatsapp? e.g.:

   if url.scheme == "whatsapp" && UIApplication.shared.canOpenURL(url) {
                UIApplication.shared.open(url, options: [:])
            }

If so I'm just curious why we're not handling this in the same way? (*To clarify, what I mean is that the code for whatsapp and the paypal/YT/insta links seems to be applying a similar fix at first glance, but the code is slightly different, but it seems like all of these could be consolidated. LMK if I'm overlooking something though)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may look the same but is a little bit different...

(few code for reference)

guard !navigationAction.isInternalUnprivileged,
             shouldRequestBeOpenedAsPopup(navigationAction.request)
       else {
           guard let url = navigationAction.request.url else { return nil }

           if url.scheme == "whatsapp" && UIApplication.shared.canOpenURL(url) {
               UIApplication.shared.open(url, options: [:])
           }

           return nil
       }

For other apps than "whatsapp" like "youtube" or "instagram", "shouldRequestBeOpenedAsPopup" method returns true because "url.scheme" is https not "youtube" or "instagram" as on "whatsapp" case. (based on the code, from above)

In this case, the logic, may be a little bit different.


// If the page uses `window.open()` or `[target="_blank"]`, open the page in a new tab.
// IMPORTANT!!: WebKit will perform the `URLRequest` automatically!! Attempting to do
// the request here manually leads to incorrect results!!
Expand Down Expand Up @@ -1079,4 +1084,14 @@ extension WKNavigationAction {
return false
}
}

var canOpenExternalApp: Bool {
guard let urlShortDomain = request.url?.shortDomain else { return false }

if let url = URL(string: "\(urlShortDomain)://"), UIApplication.shared.canOpenURL(url) {
return true
}

return false
}
}
3 changes: 3 additions & 0 deletions firefox-ios/Client/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<false/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>paypal</string>
<string>instagram</string>
<string>youtube</string>
Comment on lines +58 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused: this might work for these specific URL schemes but there is a wide variety of schemes for other apps, wouldn't they also suffer from a similar problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you right but this is the way that we can find if an app is installed or not. This apps should be manually added in this list and yea... may be other apps too.

<string>pocket</string>
<string>firefox-focus</string>
<string>firefox-klar</string>
Expand Down