Skip to content

Commit

Permalink
fire pixels when showing the error screen (#3462)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/392891325557410/1208511720659950/f
Tech Design URL:
CC:

**Description**:
Fires a pixel when the error screen is shown.

**Steps to test this PR**:
1. Open a tab, and use activity monitor to kill that process. The
"webpage has crashed" error screen should appear and the pixel should be
fired.
2. Open a nonsense url like https://nonsense.url - The 'unable to load'
page should appear and the pixel should be displayed
3. Switch between other tabs and the error pages and pixels should be
fired when the user switches tabs.

**Definition of Done**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
brindy authored Oct 28, 2024
1 parent 1316e46 commit cb1122b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DuckDuckGo/Statistics/GeneralPixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ enum GeneralPixel: PixelKitEventV2 {
case adAttributionLogicWrongVendorOnFailedCompilation

case webKitDidTerminate
case userViewedWebKitTerminationErrorPage

case removedInvalidBookmarkManagedObjects

Expand Down Expand Up @@ -424,6 +425,10 @@ enum GeneralPixel: PixelKitEventV2 {

case compilationFailed

// MARK: error page shown
case errorPageShownOther
case errorPageShownWebkitTermination

var name: String {
switch self {

Expand Down Expand Up @@ -916,6 +921,8 @@ enum GeneralPixel: PixelKitEventV2 {

case .webKitDidTerminate:
return "webkit_did_terminate"
case .userViewedWebKitTerminationErrorPage:
return "webkit-termination-error-page-viewed"

case .removedInvalidBookmarkManagedObjects:
return "removed_invalid_bookmark_managed_objects"
Expand Down Expand Up @@ -1037,6 +1044,9 @@ enum GeneralPixel: PixelKitEventV2 {
case .bookmarksSortByName: return "m_mac_sort_bookmarks_by_name"
case .bookmarksSearchExecuted: return "m_mac_search_bookmarks_executed"
case .bookmarksSearchResultClicked: return "m_mac_search_result_clicked"

case .errorPageShownOther: return "m_mac_errorpageshown_other"
case .errorPageShownWebkitTermination: return "m_mac_errorpageshown_webkittermination"
}
}

Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift

@MainActor
func webContentProcessDidTerminate(with reason: WKProcessTerminationReason?) {
guard (error?.code.rawValue ?? WKError.Code.unknown.rawValue) != WKError.Code.webContentProcessTerminated.rawValue else { return }

let error = WKError(.webContentProcessTerminated, userInfo: [
WKProcessTerminationReason.userInfoKey: reason?.rawValue ?? -1,
NSLocalizedDescriptionKey: UserText.webProcessCrashPageMessage
Expand Down
27 changes: 27 additions & 0 deletions DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ final class TabCollectionViewModel: NSObject {

subscribeToTabs()
subscribeToPinnedTabsManager()
subscribeToSelectedTab()

if tabCollection.tabs.isEmpty {
appendNewTab(with: homePage)
Expand All @@ -153,6 +154,32 @@ final class TabCollectionViewModel: NSObject {
burnerMode: burnerMode)
}

var selectedTabCancellable: AnyCancellable?
private func subscribeToSelectedTab() {
selectedTabCancellable = $selectedTabViewModel
.compactMap { $0 }
.sink { [weak self] model in
self?.subscribeToTabError(model)
}
}

var selectedTabErrorCancellable: AnyCancellable?
private func subscribeToTabError(_ model: TabViewModel) {
selectedTabErrorCancellable = model.tab.$error
.compactMap { $0 }
.sink { [weak self] error in
self?.fireErrorPageShownPixel(error)
}
}

private func fireErrorPageShownPixel(_ error: WKError) {
if error.code == WKError.Code.webContentProcessTerminated {
PixelKit.fire(GeneralPixel.errorPageShownWebkitTermination)
} else {
PixelKit.fire(GeneralPixel.errorPageShownOther)
}
}

func setUpLazyLoadingIfNeeded() {
guard !isTabLazyLoadingRequested else {
Logger.tabLazyLoading.debug("Lazy loading already requested in this session, skipping.")
Expand Down

0 comments on commit cb1122b

Please sign in to comment.