From 35670974b4b8fa94cb6dd99689bed890d30ccb14 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Mon, 27 Jan 2025 15:32:55 -0500 Subject: [PATCH 1/3] feat: Send GutenbergKit exceptions to crash logger --- .../android/ui/posts/EditPostActivity.kt | 32 +++++++++++++++++++ gradle/libs.versions.toml | 2 +- .../android/editor/AztecEditorFragment.java | 4 +++ .../editor/EditorFragmentAbstract.java | 2 ++ .../gutenberg/GutenbergEditorFragment.java | 4 +++ .../gutenberg/GutenbergKitEditorFragment.java | 7 ++++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt index b3b2b8aa32b6..96dd1ee1ea20 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt @@ -43,6 +43,7 @@ import androidx.viewpager.widget.ViewPager.SimpleOnPageChangeListener import com.automattic.android.tracks.crashlogging.CrashLogging import com.automattic.android.tracks.crashlogging.JsException import com.automattic.android.tracks.crashlogging.JsExceptionCallback +import com.automattic.android.tracks.crashlogging.JsExceptionStackTraceElement import com.google.android.material.appbar.AppBarLayout import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar @@ -251,6 +252,7 @@ import org.wordpress.gutenberg.GutenbergWebViewPool import org.wordpress.aztec.AztecExceptionHandler import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException import org.wordpress.aztec.util.AztecLog +import org.wordpress.gutenberg.GutenbergJsException import org.wordpress.gutenberg.GutenbergView import org.wordpress.gutenberg.MediaType import java.io.File @@ -2540,6 +2542,36 @@ class EditPostActivity : BaseAppCompatActivity(), EditorFragmentActivity, Editor openMediaLibrary(mediaType, initialSelection) } }) + editorFragment?.onLogJsException(object : GutenbergView.LogJsExceptionListener { + override fun onLogJsException(exception: GutenbergJsException) { + val stackTraceElements = exception.stackTrace.map { stackTrace -> + JsExceptionStackTraceElement( + stackTrace.fileName, + stackTrace.lineNumber, + stackTrace.colNumber, + stackTrace.function + ) + } + + val jsException = JsException( + exception.type, + exception.message, + stackTraceElements, + exception.context, + exception.tags, + exception.isHandled, + exception.handledBy + ) + + val callback = object : JsExceptionCallback { + override fun onReportSent(success: Boolean) { + // Do nothing + } + } + + onLogJsException(jsException, callback) + } + }) } else { editorFragment?.titleOrContentChanged?.observe(this@EditPostActivity) { _: Editable? -> storePostViewModel.savePostWithDelay() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e7721f447c48..8df34c553909 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -71,7 +71,7 @@ google-play-services-auth = '20.4.1' google-services = '4.4.2' gravatar = '2.2.0' greenrobot-eventbus = '3.3.1' -gutenberg-kit = 'trunk-cc52214a50893b41898607ac0bff7f2787b085bb' +gutenberg-kit = '64-0ba22abab1d0ba0a48449c6e9bcf1280e6abee24' gutenberg-mobile = 'v1.121.0' indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' jackson-databind = '2.12.7.1' diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java index cfff93415617..86bdc2ee15b4 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java @@ -108,6 +108,7 @@ import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; +import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.xml.sax.Attributes; @@ -718,6 +719,9 @@ public Pair getTitleAndContent(CharSequence original @Override public void onOpenMediaLibrary(@Nullable OpenMediaLibraryListener listener) { } + @Override public void onLogJsException(@NonNull LogJsExceptionListener listener) { + } + @Override public void onToolbarCollapseButtonClicked() { mEditorFragmentListener.onTrackableEvent(TrackableEvent.ELLIPSIS_COLLAPSE_BUTTON_TAPPED); diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java b/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java index 8962f822a2d7..0aeea196f4d0 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java @@ -22,6 +22,7 @@ import org.wordpress.android.util.helpers.MediaGallery; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; +import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import java.util.ArrayList; @@ -44,6 +45,7 @@ public abstract Pair getTitleAndContent(CharSequence public abstract void onEditorContentChanged(ContentChangeListener listener); public abstract void onEditorHistoryChanged(HistoryChangeListener listener); public abstract void onOpenMediaLibrary(OpenMediaLibraryListener listener); + public abstract void onLogJsException(LogJsExceptionListener listener); public abstract LiveData getTitleOrContentChanged(); public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader); public abstract void appendMediaFiles(Map mediaList); diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java index ae279371ecdc..5726953b02ff 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java @@ -67,6 +67,7 @@ import org.wordpress.aztec.IHistoryListener; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; +import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.LogExceptionCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergEmbedWebViewActivity; @@ -1266,6 +1267,9 @@ public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) { public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) { } + public void onLogJsException(@NonNull LogJsExceptionListener listener) { + } + @Override public LiveData getTitleOrContentChanged() { return mTextWatcher.getAfterTextChanged(); diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java index 0e86c1c89391..3a44f20a3983 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java @@ -45,6 +45,7 @@ import org.wordpress.gutenberg.GutenbergView; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; +import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.wordpress.gutenberg.GutenbergView.TitleAndContentCallback; import org.wordpress.gutenberg.GutenbergWebViewPool; @@ -82,6 +83,7 @@ public class GutenbergKitEditorFragment extends EditorFragmentAbstract implement @Nullable private ContentChangeListener mContentChangeListener = null; @Nullable private HistoryChangeListener mHistoryChangeListener = null; @Nullable private OpenMediaLibraryListener mOpenMediaLibraryListener = null; + @Nullable private LogJsExceptionListener mOnLogJsExceptionListener = null; private boolean mEditorDidMount; @@ -139,6 +141,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mGutenbergView.setContentChangeListener(mContentChangeListener); mGutenbergView.setHistoryChangeListener(mHistoryChangeListener); mGutenbergView.setOpenMediaLibraryListener(mOpenMediaLibraryListener); + mGutenbergView.setLogJsExceptionListener(mOnLogJsExceptionListener); mGutenbergView.setEditorDidBecomeAvailable(view -> { mEditorFragmentListener.onEditorFragmentContentReady(new ArrayList<>(), false); }); @@ -376,6 +379,10 @@ public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) { mOpenMediaLibraryListener = listener; } + public void onLogJsException(@NonNull LogJsExceptionListener listener) { + mOnLogJsExceptionListener = listener; + } + @Override public LiveData getTitleOrContentChanged() { return mTextWatcher.getAfterTextChanged(); From 3ec0495c7e68c394e5ce91a6840cf14866432a9c Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Mon, 27 Jan 2025 17:11:46 -0500 Subject: [PATCH 2/3] build: Update GutenbergKit ref --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8df34c553909..649bd2fdc19f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -71,7 +71,7 @@ google-play-services-auth = '20.4.1' google-services = '4.4.2' gravatar = '2.2.0' greenrobot-eventbus = '3.3.1' -gutenberg-kit = '64-0ba22abab1d0ba0a48449c6e9bcf1280e6abee24' +gutenberg-kit = '64-7c72b11fd9c4dba754706b4e79325f59b37ea3b6' gutenberg-mobile = 'v1.121.0' indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' jackson-databind = '2.12.7.1' From e3e4508351568ec4805fef2c1836e5e754fafbdf Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 28 Jan 2025 13:18:54 -0500 Subject: [PATCH 3/3] build: Update GutenbergKit ref --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 649bd2fdc19f..971dbd331f56 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -71,7 +71,7 @@ google-play-services-auth = '20.4.1' google-services = '4.4.2' gravatar = '2.2.0' greenrobot-eventbus = '3.3.1' -gutenberg-kit = '64-7c72b11fd9c4dba754706b4e79325f59b37ea3b6' +gutenberg-kit = 'trunk-fb31301ea6a94376237947afb4242f75c074f43c' gutenberg-mobile = 'v1.121.0' indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' jackson-databind = '2.12.7.1'