Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle debug flags sent from C-S-S #2138

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shared/js/background/broken-site-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function constructUrl (querystring, truncate) {
searchParams.delete(key)
}
})
if (searchParams.has('debugFlags')) {
extraParams += `&debugFlags=${searchParams.get('debugFlags')}`
searchParams.delete('debugFlags')
muodov marked this conversation as resolved.
Show resolved Hide resolved
}
url += `${searchParams.toString()}${extraParams}`
return url
}
Expand Down Expand Up @@ -134,6 +138,7 @@ export function breakageReportForTab ({
const ctlFacebookLogin = tab.ctlFacebookLogin ? 'true' : 'false'
const ampUrl = tab.ampUrl || undefined
const upgradedHttps = tab.upgradedHttps
const debugFlags = tab.debugFlags.map(encodeURIComponent).join(',')
muodov marked this conversation as resolved.
Show resolved Hide resolved

const brokenSiteParams = new URLSearchParams({
siteUrl,
Expand All @@ -153,6 +158,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