Skip to content

Commit

Permalink
Handle debug flags sent from C-S-S (#2138)
Browse files Browse the repository at this point in the history
* Handle debug flags sent from C-S-S

* Fix test

* Remove special treatment during debugFlags encoding
  • Loading branch information
muodov authored Jul 27, 2023
1 parent 91c076b commit bb0e54a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions shared/js/background/broken-site-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function breakageReportForTab ({
const ctlFacebookLogin = tab.ctlFacebookLogin ? 'true' : 'false'
const ampUrl = tab.ampUrl || undefined
const upgradedHttps = tab.upgradedHttps
const debugFlags = tab.debugFlags.join(',')

const brokenSiteParams = new URLSearchParams({
siteUrl,
Expand All @@ -153,6 +154,7 @@ export function breakageReportForTab ({

if (ampUrl) brokenSiteParams.set('ampUrl', ampUrl)
if (category) brokenSiteParams.set('category', category)
if (debugFlags) brokenSiteParams.set('debugFlags', debugFlags)
if (description) brokenSiteParams.set('description', description)

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

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

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

/**
* If given a valid adClick redirect, set the adClick to the tab.
* @param {string} requestURL
Expand Down
10 changes: 9 additions & 1 deletion shared/js/background/message-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ export async function isClickToLoadYoutubeEnabled () {
)
}

export function addDebugFlag (message, sender, req) {
const tab = tabManager.get({ tabId: sender.tab.id })
const flags = new Set(tab.debugFlags)
flags.add(message.flag)
tab.debugFlags = [...flags]
}

/**
* Add a new message handler.
* @param {string} name
Expand Down Expand Up @@ -522,6 +529,7 @@ const messageHandlers = {
debuggerMessage,
search,
openShareFeedbackPage,
isClickToLoadYoutubeEnabled
isClickToLoadYoutubeEnabled,
addDebugFlag
}
export default messageHandlers
1 change: 1 addition & 0 deletions shared/js/content-scripts/content-scope-messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const allowedMessages = [
'getClickToLoadState',
'getYouTubeVideoDetails',
'openShareFeedbackPage',
'addDebugFlag',
'setYoutubePreviewsEnabled',
'unblockClickToLoadContent',
'updateYouTubeCTLAddedFlag',
Expand Down
3 changes: 2 additions & 1 deletion unit-test/background/classes/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ describe('Tab', () => {
statusCode: null,
ctlYouTube: false,
ctlFacebookPlaceholderShown: false,
ctlFacebookLogin: false
ctlFacebookLogin: false,
debugFlags: []
}
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 bb0e54a

Please sign in to comment.