fix: keep navbar spacer visible under browser cosmetic filters

Merged
BO
2mo ago
+120-5

What does this PR aim to accomplish?:

Closes #1041.

The navbar spacer's inline style matches a browser-injected cosmetic filter shown in the maintainer's reproduction video: body > [style^="display: block; width: 100%; height:"]:empty { display: none !important; }. The filter hides the spacer while the fixed navbar remains visible, so the first content is covered even though Bootstrap loaded successfully. Toggling display in DevTools changes the serialized property order and stops the filter matching, explaining the reported workaround and profile-dependent reproduction.

Evidence: maintainer reproduction. This reproduces the recorded browser rule; the previous Bootstrap-loading fix addressed a separate failure condition.

How does this PR accomplish the above?:

Move the spacer's static display and width rules into a stylesheet owned by NavbarStyler. Only its measured height remains inline, so it no longer matches the recorded filter. The stylesheet works before Bootstrap arrives, is reused on refresh, is recreated if detached, and is removed on teardown. Existing page-owned spacers that match the recorded rule have their inline display and width moved to the stylesheet too. Teardown restores their original height, display, width and declaration order while retaining unrelated styles added or changed by the page. Nonmatching page-owned spacers keep their layout declarations. The span element still avoids legacy body > div selectors, preserving the downloads fix.

Validation: all 91 npm tests pass in installed Chromium, including a new regression with the exact recorded filter. It fails on the merged code and passes after this change, checking computed visibility, reserved height and content clearance after resizing, navbar replacement and teardown. It also covers a borrowed spacer with the old inline fingerprint, restoring its declaration order and retaining a page-added color. Existing tests cover Bootstrap-delayed layout, downloads, listener ownership, original styles, borrowed spacer/overlay preservation and Chinese font rendering. Userscript syntax and diff whitespace checks also pass. No new dependency was added.

Please verify the installed userscript in both the new and classic UIs, ideally with the affected browser profile, before confirming template item 11. The final checklist remains unchecked; automated browser fixtures do not claim this human verification.


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributor's guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented on my proposed changes within the code.
  3. I have tested my changes.
  4. I am willing to help maintain this change if there are issues with it later.
  5. It is compatible with the GNU General Public License v3.0
  6. I have squashed any insignificant commits. (git rebase)
  7. I have checked that another pull request for this purpose does not exist.
  8. I have considered and confirmed that this submission will be valuable to others.
  9. I accept that this submission may not be used, and the pull request can be closed at the will of the maintainer.
  10. I give this submission freely and claim no ownership to its content.
  11. I have verified that my changes work correctly in both the new UI and the old/classic UI.

  • I have read the above and my PR is ready for review. Check this box to confirm

Summary by Sourcery

Keep the navbar spacer visible and restore page-owned spacer styles safely when cosmetic filters target its inline declarations.

Bug Fixes:

  • Prevent browser cosmetic filters from hiding the navbar spacer and obscuring the page’s first content.
  • Preserve borrowed spacer styles and declaration order during cleanup while retaining unrelated page changes.

Enhancements:

  • Manage navbar spacer layout rules through a reusable stylesheet that remains available across delayed Bootstrap loading, refreshes, navbar replacement, and teardown.

Build:

  • Bump the userscript and package versions to 3.8.4 and add update metadata.

Tests:

  • Add Chromium regression coverage for the recorded cosmetic filter, dynamic navbar sizing, navbar replacement, teardown, and restoration of page-owned spacer styles.