bilibili/flv.js · error · RuntimeException

MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' +

Error message

MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText

What it means

MozChunkedLoader (Firefox moz-chunked-xhr path) checks the HTTP status at readyState 2 (HEADERS_RECEIVED). Any status outside 200-299 (and not 0) is treated as a fatal load error: the loader enters kError and, if no onError callback is set, throws RuntimeException including the numeric status and statusText.

Source

Thrown at src/io/xhr-moz-chunked-loader.js:143

    }

    _onReadyStateChange(e) {
        let xhr = e.target;

        if (xhr.readyState === 2) {  // HEADERS_RECEIVED
            if (xhr.responseURL != undefined && xhr.responseURL !== this._requestURL) {
                if (this._onURLRedirect) {
                    let redirectedURL = this._seekHandler.removeURLParameters(xhr.responseURL);
                    this._onURLRedirect(redirectedURL);
                }
            }

            if (xhr.status !== 0 && (xhr.status < 200 || xhr.status > 299)) {
                this._status = LoaderStatus.kError;
                if (this._onError) {
                    this._onError(LoaderErrors.HTTP_STATUS_CODE_INVALID, {code: xhr.status, msg: xhr.statusText});
                } else {
                    throw new RuntimeException('MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);
                }
            } else {
                this._status = LoaderStatus.kBuffering;
            }
        }
    }

    _onProgress(e) {
        if (this._status === LoaderStatus.kError) {
            // Ignore error response
            return;
        }

        if (this._contentLength === null) {
            if (e.total !== null && e.total !== 0) {
                this._contentLength = e.total;
                if (this._onContentLengthKnown) {
                    this._onContentLengthKnown(this._contentLength);

View on GitHub (pinned to 42343088f2)

Solutions

  1. Check the reported status/statusText and fix the server side: verify the FLV URL exists (curl -I) and permissions/tokens are valid.
  2. Register onError to receive LoaderErrors.HTTP_STATUS_CODE_INVALID instead of an uncaught throw.
  3. Refresh or re-sign the CDN URL and retry; add fallback URL logic.

Example fix

// before
player.load(); // 403 from expired token not handled
// after
player.on(flvjs.Events.ERROR, (type, data) => {
    if (data.code === 403) refreshSignedUrlAndReload();
});
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight check before starting Firefox chunked load
fetch(streamUrl, {method: 'HEAD'}).then(r => {
    if (!r.ok) throw new Error('Stream URL not reachable: ' + r.status);
    startPlayer();
});

Try / catch

try {
    player.load();
} catch (e) {
    if (/MozChunkedLoader: Http code invalid/.test(e.message)) {
        const m = e.message.match(/invalid, (\d+)/);
        handleHttpFailure(m ? Number(m[1]) : 0);
    } else throw e;
}

Prevention

When it happens

Trigger: The XHR for the FLV stream completes headers with a non-2xx status — e.g. 404 for a removed file, 403 for expired/missing auth token, 5xx from an overloaded server — in _onReadyStateChange (src/io/xhr-moz-chunked-loader.js:143).

Common situations: Expired signed CDN URLs, wrong stream path, CORS/auth failures, or the stream URL pointing to an error page instead of media; commonly seen in Firefox only since this loader is the Firefox code path.

Related errors


AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01). Data as JSON: /api/errors/c05d425103ab727c. Report an issue: GitHub.