From cfd8b514dab6ec1c6313dc131271f4d5218c733e Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Mon, 17 Jun 2024 11:34:46 -0400 Subject: [PATCH] Check that the jsobject has not been added already --- .../wordpress/android/ui/reader/ReaderPostRenderer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostRenderer.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostRenderer.java index c7157a096ebe..d5ce0cea398c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostRenderer.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostRenderer.java @@ -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; @@ -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 allowedOrigins = new HashSet<>(); allowedOrigins.add("*"); @@ -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) {