diff --git a/shared/js/background/broken-site-report.js b/shared/js/background/broken-site-report.js index 0e024a1a17..51f8ead571 100644 --- a/shared/js/background/broken-site-report.js +++ b/shared/js/background/broken-site-report.js @@ -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, @@ -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()) } diff --git a/shared/js/background/classes/tab-state.js b/shared/js/background/classes/tab-state.js index 5c1b4f2ab3..06d6b39f60 100644 --- a/shared/js/background/classes/tab-state.js +++ b/shared/js/background/classes/tab-state.js @@ -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) diff --git a/shared/js/background/classes/tab.js b/shared/js/background/classes/tab.js index f33a96ee0e..06da53b741 100644 --- a/shared/js/background/classes/tab.js +++ b/shared/js/background/classes/tab.js @@ -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 diff --git a/shared/js/background/components/tab-tracking.js b/shared/js/background/components/tab-tracking.js index 0de2373de0..9d3e306c66 100644 --- a/shared/js/background/components/tab-tracking.js +++ b/shared/js/background/components/tab-tracking.js @@ -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) diff --git a/shared/js/background/events.js b/shared/js/background/events.js index a8e4499c4e..cbdfe512c3 100644 --- a/shared/js/background/events.js +++ b/shared/js/background/events.js @@ -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) { diff --git a/unit-test/background/classes/tab.js b/unit-test/background/classes/tab.js index 2fb5d9d60e..d710f12799 100644 --- a/unit-test/background/classes/tab.js +++ b/unit-test/background/classes/tab.js @@ -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))