Skip to content

[BUG FIX] fix memory leakage & object properties exposure & TTP xml parse fallback to null#1242

Open
cyfung1031 wants to merge 1 commit intoscriptscat:mainfrom
cyfung1031:fix-xhr-impl-401
Open

[BUG FIX] fix memory leakage & object properties exposure & TTP xml parse fallback to null#1242
cyfung1031 wants to merge 1 commit intoscriptscat:mainfrom
cyfung1031:fix-xhr-impl-401

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Feb 13, 2026

Description

This PR fixes three closely related issues in the GM_xmlhttpRequest implementation to improve compatibility with Tampermonkey (TM), prevent memory leaks, and handle Trusted Types Policy (TTP) environments safely.

Changes

  • Non-enumerable response getters
    response, responseText and responseXML are now defined with non-enumerable getters (enumerable: false), matching Tampermonkey behavior.
    This prevents Object.assign({}, response), JSON.stringify(response), or similar operations from unintentionally triggering getters or exposing internal state.

  • Memory leak fix via weak references
    Internal state is now managed through a WeakMap. Getters are attached lazily only after readyState === 4.
    This allows the garbage collector to reclaim memory once the consumer no longer references the response/XHR object, eliminating closure-induced leaks.

  • Safe fallback for responseXML in TTP-restricted pages
    When DOMParser.parseFromString() fails due to Trusted Types violations (or other parse errors), responseXML now returns null instead of throwing.
    This matches Tampermonkey's observed behavior in restricted environments.

Related issues

#1239 is a combination symptom of #1240 + #1241 (only reproducible when both conditions are met)

Important notes

  • This PR does not attempt to bypass or work around Trusted Types restrictions.
  • Scriptcat aligns strictly with Tampermonkey & Violentmonkey behavior in TTP-protected pages.
  • No new dependencies or large refactors — change is localized to the GM_xmlhttpRequest logic.

@cyfung1031 cyfung1031 added hotfix 需要尽快更新到扩展商店 compatibility 其它管理器可以运行,脚本猫不能运行 labels Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility 其它管理器可以运行,脚本猫不能运行 hotfix 需要尽快更新到扩展商店

Projects

None yet

1 participant