From ab5b72f16d1db4d07908516283bbd00d985821ca Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 15 Apr 2026 23:35:02 -0400 Subject: [PATCH] Fix cookies page settings override after upstream 3PCD cleanup (#35543) * Fix cookies page settings override after upstream 3PCD cleanup Chromium removed the dom-if template with `is3pcdRedesignEnabled_` as part of the 3PCD experiment cleanup. The #generalControls element still exists but is no longer wrapped in a conditional template, so find it directly on templateContent like the other elements. * Fix settings search crash in site settings page The getAssociatedControlFor override was using querySelector on the page's shadow root, but list item link rows (e.g. #autoplay, #ethereum) are rendered inside settings-site-settings-list shadow DOMs. The querySelector couldn't find them, falling through to the base mixin's assertNotReached(). Search through the list components' shadow DOMs instead. --- browser/resources/settings/br/cookies_page.ts | 21 +++++-------------- .../settings/br/site_settings_page.ts | 18 +++++++++++++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/browser/resources/settings/br/cookies_page.ts b/browser/resources/settings/br/cookies_page.ts index d1d13edd6fa..dfda0993922 100644 --- a/browser/resources/settings/br/cookies_page.ts +++ b/browser/resources/settings/br/cookies_page.ts @@ -15,24 +15,13 @@ import { SettingsCookiesPageElement } from '../privacy_page/cookies_page.js' RegisterPolymerTemplateModifications({ 'settings-cookies-page': (templateContent) => { - const isNot3pcdRedesignEnabledTemplate = templateContent. - querySelector( - 'template[if*="!is3pcdRedesignEnabled_"]' - ) - if (!isNot3pcdRedesignEnabledTemplate) { + const generalControls = templateContent.getElementById('generalControls') + if (!generalControls) { console.error( - '[Brave Settings Overrides] Could not find template with ' + - 'if*=!is3pcdRedesignEnabledTemplate on cookies page.') + '[Brave Settings Overrides] Could not find generalControls id ' + + 'on cookies page.') } else { - const generalControls = isNot3pcdRedesignEnabledTemplate.content. - getElementById('generalControls') - if (!generalControls) { - console.error( - '[Brave Settings Overrides] Could not find generalControls id ' + - 'on cookies page.') - } else { - generalControls.setAttribute('hidden', 'true') - } + generalControls.setAttribute('hidden', 'true') } const additionalProtections = templateContent. getElementById('additionalProtections') diff --git a/browser/resources/settings/br/site_settings_page.ts b/browser/resources/settings/br/site_settings_page.ts index c4da158d470..064a209ff30 100644 --- a/browser/resources/settings/br/site_settings_page.ts +++ b/browser/resources/settings/br/site_settings_page.ts @@ -202,9 +202,21 @@ RegisterPolymerComponentReplacement( } override getAssociatedControlFor(childViewId: string): HTMLElement { - // Note: We use the ContentSettingsTypes.XXX as the childViewId and the id to the link for opening it. - const maybeChild = this.shadowRoot?.querySelector(`#${childViewId}`) as HTMLElement | null - return maybeChild ?? super.getAssociatedControlFor(childViewId) + // Link rows for each setting are rendered inside + // settings-site-settings-list shadow DOMs, not directly in this page's + // shadow root, so we need to search through them. + const lists = this.shadowRoot?.querySelectorAll( + 'settings-site-settings-list') + if (lists) { + for (const list of lists) { + const child = list.shadowRoot?.querySelector( + `#${childViewId}`) as HTMLElement | null + if (child) { + return child + } + } + } + return super.getAssociatedControlFor(childViewId) } } )