Skip to content

Commit

Permalink
Add site breakage reasons to reports. (#2278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed Oct 20, 2023
1 parent edafd25 commit a6654f2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions shared/js/background/broken-site-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export function breakageReportForTab ({
const ampUrl = tab.ampUrl || undefined
const upgradedHttps = tab.upgradedHttps
const debugFlags = tab.debugFlags.join(',')
const errorDescriptions = JSON.stringify(tab.errorDescriptions)
const httpErrorCodes = tab.httpErrorCodes.join(',')

const brokenSiteParams = new URLSearchParams({
siteUrl,
Expand All @@ -156,6 +158,8 @@ export function breakageReportForTab ({
if (category) brokenSiteParams.set('category', category)
if (debugFlags) brokenSiteParams.set('debugFlags', debugFlags)
if (description) brokenSiteParams.set('description', description)
if (errorDescriptions) brokenSiteParams.set('errorDescriptions', errorDescriptions)
if (httpErrorCodes) brokenSiteParams.set('httpErrorCodes', httpErrorCodes)

return fire(brokenSiteParams.toString())
}
4 changes: 4 additions & 0 deletions shared/js/background/classes/tab-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class TabState {
this.denylisted = false
/** @type {string[]} */
this.debugFlags = []
/** @type {string[]} */
this.errorDescriptions = []
/** @type {number[]} */
this.httpErrorCodes = []
// Whilst restoring, prevent the tab data being stored
if (!restoring) {
Storage.backup(this)
Expand Down
16 changes: 16 additions & 0 deletions shared/js/background/classes/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ class Tab {
this._tabState.setValue('debugFlags', value)
}

get errorDescriptions () {
return this._tabState.errorDescriptions
}

set errorDescriptions (value) {
this._tabState.setValue('errorDescriptions', value)
}

get httpErrorCodes () {
return this._tabState.httpErrorCodes
}

set httpErrorCodes (value) {
this._tabState.setValue('httpErrorCodes', value)
}

/**
* If given a valid adClick redirect, set the adClick to the tab.
* @param {string} requestURL
Expand Down
3 changes: 3 additions & 0 deletions shared/js/background/components/tab-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default class TabTracker {
browser.webRequest.onHeadersReceived.addListener((request) => {
this.tabManager.updateTabUrl(request)
const tab = tabManager.get({ tabId: request.tabId })

tab.httpErrorCodes.push(request.statusCode)

// SERP ad click detection
if (
isRedirect(request.statusCode)
Expand Down
2 changes: 2 additions & 0 deletions shared/js/background/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ browser.webRequest.onErrorOccurred.addListener(e => {

const tab = tabManager.get({ tabId: e.tabId })

tab.errorDescriptions.push(e.error)

// We're only looking at failed main_frame upgrades. A tab can send multiple
// main_frame request errors so we will only look at the first one then set tab.hasHttpsError.
if (!tab || !tab.mainFrameUpgraded || tab.hasHttpsError) {
Expand Down
4 changes: 3 additions & 1 deletion unit-test/background/classes/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ describe('Tab', () => {
ctlYouTube: false,
ctlFacebookPlaceholderShown: false,
ctlFacebookLogin: false,
debugFlags: []
debugFlags: [],
errorDescriptions: [],
httpErrorCodes: []
}
expect(tabClone.site.enabledFeatures.length).toBe(14)
expect(JSON.stringify(tabClone, null, 4)).toEqual(JSON.stringify(tabSnapshot, null, 4))
Expand Down

0 comments on commit a6654f2

Please sign in to comment.