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

[Fix] IllegalArgumentException: in ReaderPostRenderer #20997

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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 @@ -48,6 +48,7 @@
*/
public class ReaderPostRenderer {
private static final String JAVASCRIPT_MESSAGE_HANDLER = "wvHandler";
private static final String JS_OBJECT_ADDED_TAG = "jsObjectAdded";
private final ReaderResourceVars mResourceVars;
private final ReaderPost mPost;
private final int mMinFullSizeWidthDp;
Expand Down Expand Up @@ -645,6 +646,11 @@ private String getContentTextProperties() {
}

private void setWebViewMessageHandler(@NonNull WebView webView) {
Object tag = webView.getTag(JS_OBJECT_ADDED_TAG.hashCode());
if (tag != null && (boolean) tag) {
return; // Exit if the object has already been added
}

Set<String> allowedOrigins = new HashSet<>();
allowedOrigins.add("*");

Expand All @@ -665,6 +671,9 @@ private void setWebViewMessageHandler(@NonNull WebView webView) {
}
return null;
});

// Set the tag that the JS object has been added, so we can check before adding it again
webView.setTag(JS_OBJECT_ADDED_TAG.hashCode(), true);
}

void setPostMessageListener(@Nullable ReaderPostMessageListener listener) {
Expand Down
Loading