diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java index cfe0b3bdd8c8..6a8251a7b784 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java @@ -348,8 +348,17 @@ private void initViewModel(WPWebViewUsageCategory webViewUsageCategory) { }); mViewModel.getOpenExternalBrowser().observe(this, unit -> { - ReaderActivityLauncher.openUrl(WPWebViewActivity.this, mWebView.getUrl(), - ReaderActivityLauncher.OpenUrlType.EXTERNAL); + // Prefer the currently loaded URL, but fall back to the requested URL when the page + // hasn't finished loading yet (mWebView.getUrl() is null before the first load). + String urlToOpen = mWebView.getUrl(); + if (TextUtils.isEmpty(urlToOpen)) { + Bundle extras = getIntent().getExtras(); + urlToOpen = extras != null ? extras.getString(URL_TO_LOAD) : null; + } + if (!TextUtils.isEmpty(urlToOpen)) { + ReaderActivityLauncher.openUrl(WPWebViewActivity.this, urlToOpen, + ReaderActivityLauncher.OpenUrlType.EXTERNAL); + } }); mViewModel.getPreviewModeSelector().observe(this, previewModelSelectorStatus -> { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java index f4f29c7ebb9b..3af314d15b01 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java @@ -831,7 +831,7 @@ private void showCommentWhenNonNull( updateStatusViews(binding, actionBinding, site, comment, note); // navigate to author's blog when avatar or name clicked - if (comment.getAuthorUrl() != null) { + if (!TextUtils.isEmpty(comment.getAuthorUrl())) { View.OnClickListener authorListener = v -> ReaderActivityLauncher.openUrl(getActivity(), comment.getAuthorUrl()); binding.imageAvatar.setOnClickListener(authorListener);