Uncaught TypeError when assigning null to xhr.onreadystatechange/onprogress (breaks hls.js abort)

オープン 初心者向け
#740 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@cyhano がすでに取り組んでいます。

2026年9月15日 から。

  • #741 @cyhano による — オープン
  • #747 @lnuxe による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
frontend, tooling

調査の方向性

src/network/xhr.proxy.ts から始めて、setOnReadyStateChange、setOnAbort、setOnTimeout を調べます。提供された XMLHttpRequest スニペットで問題を再現し、その後、null または undefined を代入してもコールバックのラップや中断時の例外が発生しないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

Description

Libraries like hls.js clear XHR event callbacks before aborting in-flight requests (see XhrLoader.abortInternal in hls.js):

xhr.onreadystatechange = null;
xhr.onprogress = null;
xhr.abort();

With vConsole enabled, this throws an uncaught TypeError, because the XHR proxy wraps whatever value is assigned to onreadystatechange / onabort / ontimeout without a null check — the wrapper later calls value.apply(...) on null.

src/network/xhr.proxy.ts (still present on current master):

protected setOnReadyStateChange(target: T, key: string, value) {
  ...
  Reflect.set(target, key, function () {
    ...
    value.apply(target, args);   // 💥 value may be null
  });
}
// setOnAbort / setOnTimeout have the same problem

Assigning null to these callbacks is a legitimate, spec-compliant way to remove them, so the proxy should pass null through instead of wrapping it.

Steps to reproduce

<script src="https://unpkg.com/[email protected]/dist/vconsole.min.js"></script>
<script>
  new VConsole();
  var xhr = new XMLHttpRequest();
  xhr.open('GET', '/');                 // any URL
  xhr.onreadystatechange = function () {};
  xhr.send();
  xhr.onreadystatechange = null;        // how hls.js abortInternal cleans up
  xhr.onprogress = null;
  xhr.abort();                          // → Uncaught TypeError: Cannot read properties of null (reading 'apply')
</script>

Running the exact same code without vConsole produces no error (verified side by side).

Real-world impact

Any page playing HLS video via hls.js throws this on every stream switch / stop / destroy:

Uncaught TypeError: Cannot read property 'apply' of null
    at XMLHttpRequest.<anonymous> (vconsole.js)
    at t.r.abortInternal (hls.min.js)
    at t.abort (hls.min.js)
    at e.t.abort (hls.min.js)
    at t.r.stopLoad (hls.min.js)
    ...

Environment

  • vConsole version: 3.15.1 (latest release; null check also missing on current master)
  • Browser: any (reproduced in Chrome)

Suggested fix

Pass null/undefined through instead of wrapping it, in all three setters:

protected setOnReadyStateChange(target: T, key: string, value) {
  if (!value) return Reflect.set(target, key, value);
  ...
}
主要言語
TypeScript
スター
17.5k
フォーク
3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Tencent/vConsole のほかの issue

Tencent/vConsole の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。