Conversation
…pping them
Libraries like hls.js clear XHR event callbacks before aborting
in-flight requests (XhrLoader.abortInternal):
xhr.onreadystatechange = null;
xhr.onprogress = null;
xhr.abort();
Assigning null to these callbacks is a spec-compliant way to remove
them, but the XHR proxy wrapped whatever value was assigned, so the
wrapper later crashed with an uncaught TypeError when the event fired:
Uncaught TypeError: Cannot read properties of null (reading 'apply')
at XMLHttpRequest.<anonymous> (vconsole.min.js)
at abortInternal (hls.js)
...
Pass null/undefined through to the real XHR instead of wrapping them,
in setOnReadyStateChange / setOnAbort / setOnTimeout.
Verified with a minimal repro (vConsole + xhr.onreadystatechange = null
+ xhr.abort()): master throws the TypeError, this patch does not; normal
callbacks are still wrapped and tracked in the Network panel.
Fixes Tencent#740
Co-Authored-By: ZCode <noreply@z.ai>
Member
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.
Fixes #740
Problem
Libraries like hls.js clear XHR event callbacks before aborting in-flight requests (
XhrLoader.abortInternal):With vConsole enabled this throws an uncaught TypeError, because the XHR proxy wraps whatever value is assigned to
onreadystatechange/onabort/ontimeoutwithout a nullish check — the wrapper then callsvalue.apply(...)onnullwhen the event fires:Any page playing HLS video via hls.js hits this on every stream switch / stop / destroy. Assigning
nullto these callbacks is a spec-compliant way to remove them, so the proxy should pass nullish values through instead of wrapping them.Fix
In
setOnReadyStateChange/setOnAbort/setOnTimeout: if the assigned value is nullish,Reflect.setit directly on the real XHR instead of installing a wrapper (a comment documents why).Verification
Minimal repro (
new VConsole()+ the cleanup sequence above), run headless in Chromium:pageerrorCannot read properties of null (reading 'apply')status=200)status=200(including one whose lifecycle wentfn → null → fn)Also verified that a callback re-assigned after being cleared with
nullis wrapped and tracked again as before.