Skip to content

Commit

Permalink
Tracks Webview Large Payload error
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Feb 7, 2024
1 parent 910d3c9 commit 13a66d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.util.extensions.CompatExtensionsKt;

import java.util.HashMap;
import java.util.Map;

/**
Expand Down Expand Up @@ -90,13 +92,18 @@ protected void loadContent() {
protected void onSaveInstanceState(@NonNull Bundle outState) {
mWebView.saveState(outState);

// If the WebView state is too large, remove it from the bundle. This workaround is
// If the WebView state is too large, remove it from the bundle and track the error. This workaround is
// necessary since the Android system cannot handle large states without a crash.
// Note that Chromium `WebViewBrowserFragment` uses a similar workaround for this issue:
// https://source.chromium.org/chromium/chromium/src/+/27a9bbd3dcd7005ac9f3862dc2e356b557023de9
byte[] webViewState = outState.getByteArray(WEBVIEW_CHROMIUM_STATE);
if (webViewState != null && webViewState.length > WEBVIEW_CHROMIUM_STATE_THRESHOLD) {
outState.remove(WEBVIEW_CHROMIUM_STATE);

// Track the error to better understand the root of the issue
Map<String, String> properties = new HashMap<>();
properties.put(URL, mWebView.getUrl());
AnalyticsTracker.track(AnalyticsTracker.Stat.WEBVIEW_TOO_LARGE_PAYLOAD_ERROR, properties);
}
super.onSaveInstanceState(outState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,8 @@ public enum Stat {
SITE_MONITORING_SCREEN_SHOWN,
OPENED_SITE_MONITORING,
SITE_MONITORING_TAB_SHOWN,
SITE_MONITORING_TAB_LOADING_ERROR
SITE_MONITORING_TAB_LOADING_ERROR,
WEBVIEW_TOO_LARGE_PAYLOAD_ERROR,
}

private static final List<Tracker> TRACKERS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) {
return "site_monitoring_tab_shown";
case SITE_MONITORING_TAB_LOADING_ERROR:
return "site_monitoring_tab_loading_error";
case WEBVIEW_TOO_LARGE_PAYLOAD_ERROR:
return "webview_too_large_payload_error";
}
return null;
}
Expand Down

0 comments on commit 13a66d4

Please sign in to comment.