[BUG FIX] fix memory leakage & object properties exposure & TTP xml parse fallback to null#1242
Open
cyfung1031 wants to merge 1 commit intoscriptscat:mainfrom
Open
[BUG FIX] fix memory leakage & object properties exposure & TTP xml parse fallback to null#1242cyfung1031 wants to merge 1 commit intoscriptscat:mainfrom
cyfung1031 wants to merge 1 commit intoscriptscat:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes three closely related issues in the
GM_xmlhttpRequestimplementation to improve compatibility with Tampermonkey (TM), prevent memory leaks, and handle Trusted Types Policy (TTP) environments safely.Changes
Non-enumerable response getters
response,responseTextandresponseXMLare 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 afterreadyState === 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),responseXMLnow returnsnullinstead 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