Skip to content

fix: prevent remove_overlay_elements from deleting html/body tags - #2164

Closed
Battleplus wants to merge 2 commits into
unclecode:mainfrom
Battleplus:fix/2161-overlay-no-remove-body
Closed

fix: prevent remove_overlay_elements from deleting html/body tags#2164
Battleplus wants to merge 2 commits into
unclecode:mainfrom
Battleplus:fix/2161-overlay-no-remove-body

Conversation

@Battleplus

Copy link
Copy Markdown

这次改了什么

remove_overlay_elements 脚本在清理弹窗/overlay 时,会误删 <body><html> 元素。原因是部分 WordPress 主题(如 Bridge)在 <body> 上添加了包含 "popup" 的 class,导致 querySelectorAll('[class*="popup"]') 匹配到 body 并将其移除,整个页面变空白。

修法:在两处移除循环中添加 tagName 守卫:

  1. 高 z-index / fixed / absolute 元素移除循环
  2. 常见选择器(popup/modal/overlay)匹配移除循环

两处都跳过 HTMLBODY 标签。

怎么验证的

  • 现有 test_remove_overlay_elements 测试通过
  • 手动验证:构造 <body class="popup-overlay"> 页面,确认 body 不被移除

风险

极低。只增加两个 tagName 检查,不影响任何现有 overlay 清理逻辑。html/body 本来就不应该被移除。

Closes #2161

Resolves unclecode#2161

The remove_overlay_elements script could remove the entire page body
when it matched common overlay selectors (e.g. class containing
"popup"). Some popular WordPress themes (Bridge) add a class with
"popup" to the body tag, causing the whole page to be stripped.

Added tagName guards to both the high-z-index removal loop and the
common-selectors removal loop so that html and body elements are
never removed by the overlay cleanup logic.
Signed-off-by: Battleplus <3559424769@qq.com>
@Battleplus

Copy link
Copy Markdown
Author

Follow-up audit found one remaining removal path: the final fixed/sticky-element pass could still delete a position-fixed body. The guard is now shared across all three passes and protects HTML, HEAD, and BODY. Added a browser regression test covering popup/modal classes, a fixed body, and removal of the real modal. Validation: node --check passed; pytest tests/browser/test_overlay_document_structure.py: 1 passed. Commit: ccc9003.

@Battleplus

Copy link
Copy Markdown
Author

Closing as a duplicate after the full audit. Earlier PR #2163 protects HTML, HEAD, and BODY in all three overlay-removal passes and includes two browser regressions for popup-class and position-fixed body cases. The follow-up here found and fixed the same final fixed/sticky pass, but #2163 is earlier and more comprehensive.

@Battleplus Battleplus closed this Aug 22, 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.

[Bug]: remove_overlay_elements can remove body if it has a global popup class

1 participant