Skip to content

Fix: resolve Video Filters CSP TrustedHTML violation and toggle deactivation - #4376

Merged
ImprovedTube2 merged 2 commits into
code-charity:masterfrom
DivyaRaval1909:fix/video-filters-csp-and-toggle
Oct 10, 2026
Merged

ImprovedTube2 merged 2 commits into
code-charity:masterfrom
DivyaRaval1909:fix/video-filters-csp-and-toggle

Conversation

@DivyaRaval1909

Copy link
Copy Markdown
Member

Resolves #4374

Summary

This PR completely resolves the CSP / TrustedHTML violations and toggle deactivation issues affecting the Video Filters feature.

Details & Fixes

  1. CSP & TrustedHTML Compliance (appearance.js):
    • Replaced direct svgEl.innerHTML string assignments with safe DOM methods (document.createElementNS, setAttribute, textContent = ''), eliminating Content Security Policy and TrustedHTML sink violations on YouTube in modern Chromium and Firefox.
  2. Proper Cleanup on Deactivation (appearance.js):
    • Removed the premature guard condition (if (!isEnabled) return;) that was returning before reaching styleEl.remove() and svgEl.remove() when video_filters_activate was turned OFF.
    • Turning Activate OFF in the menu or player button now cleanly removes the injected <style> and <svg> elements from the DOM and immediately restores the video back to normal.
  3. Player Button Toggle State & UI Sync (player.js):
    • Fixed the toggle check (ImprovedTube.storage.video_filters_activate !== true) to properly handle when the storage key is unset/removed (undefined), enabling reliable back-and-forth toggling between ON and OFF.
    • When toggled ON with default/normal settings, defaults preset to 'vivid' so changes are immediately apparent.
    • Synchronizes button opacity and .it-video-filters-active CSS class on toggle.

Testing

  • Verified filter presets (Vivid, Cinema, Warm, Cool, Normal) apply without any CSP / TrustedHTML console violations.
  • Verified turning Activate OFF in the popup menu immediately removes the filter and restores video appearance.
  • Verified clicking the player button reliably toggles between Filters: ON and Filters: OFF and updates styles/button appearance.
  • Verified Shift+Click on the player button cycles through presets as expected.
  • Checked formatting with git diff --check.

@hkzo

hkzo commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for the fixes! I tested this PR in Firefox and Google Chrome and confirmed that:

  • Presets and Custom adjustments apply without CSP / TrustedHTML errors.
  • Turning Activate OFF immediately removes the filter.
  • The player button toggles ON/OFF correctly.
  • The OFF state is preserved after reloading and navigating to another video.
  • With the preset in its initial state or set to Normal and all sliders at their default values, turning filters ON via the player button switches the preset to Vivid. This automatic switch does not occur when any slider has a non-default value.

However, I noticed a button appearance issue in the following case:

  1. Turn Activate ON, select Custom, and set Brightness to 50.
  2. Select Normal in the Video Filters menu. The video returns to its normal appearance, and the player button becomes dim and loses its blue highlight. Leave Activate ON and Brightness at 50.
  3. Go to Player → Buttons and turn Video Filters button OFF, then ON again, to hide and show the button.

After the button reappears, it is highlighted blue even though the preset is still Normal and no filter effect is applied to the video.

I would expect the button to remain dim without the blue highlight, as it was before hiding it, since the filter settings and the video appearance have not changed.

Could you please take a look at why the button's appearance changes after hiding and showing it?

Separately, there are a couple of possible usability improvements for future consideration:

  • One option would be to switch to Custom when a slider is adjusted, or disable sliders while another preset is selected.
  • It might also help to align preset selection in the menu with Shift+Click: selecting Normal would turn Activate OFF, and selecting another preset would turn it ON.

These are suggestions for future consideration, and I do not consider them blockers for merging this PR.
They are separate from the button appearance issue reported above.

- Align isActive calculation with preset logic so 'normal' preset keeps button dim even if custom slider values are present in storage
- Ensure .it-video-filters-active is removed when button is initialized in inactive state
@DivyaRaval1909

Copy link
Copy Markdown
Member Author

Hi @hkzo,

Thank you for the thorough testing and detailed report!

I have investigated and fixed the button appearance issue in commit 54b8376.

Cause:

When re-creating the button in playerVideoFiltersButton(), isActive was evaluating slider values with || without checking if the active preset was custom. Because non-default custom slider values remain saved in storage when switching to Normal, the button was incorrectly initialized as active.

Fix:

Updated playerVideoFiltersButton() to compute effective values based on the active preset (matching appearance.js). When preset === 'normal', slider values are ignored, ensuring the button initializes dim without the blue highlight.

Also, thank you for the usability suggestions regarding automatic switching to Custom and menu/toggle alignment—those are great points for future follow-up iterations.

@hkzo

hkzo commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Awesome!
The button appearance now behaves exactly as expected in Firefox and Chrome.
Thank you so much! From my side, this is ready to be merged.

@ImprovedTube2
ImprovedTube2 merged commit 6219aec into code-charity:master Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞PR #4112 Video Filters fail to set innerHTML on YouTube

3 participants