Repository navigation
background: stream detection and MPV mode in modules of their own - #633
Merged
Merged
Conversation
The first step of splitting background.mjs (4,880 lines). What onHeadersReceived decided about a response - nothing, a subtitle file, or a stream and its player mode - is now classifyResponse(details, firstAddress, matcher), moved with its helpers (urlType, modeFromQuery, isHtmlResponse, isRedirect, redirectedType, modeFromRedirectQuery) and their comments word for word; the custom source patterns and a redirect's first address are parameters instead of module state. The listener keeps its side effects and their order. isSubtitles moved with them (BackgroundUtils.isSubtitles delegates), so the module needs no chrome API and is tested by itself: StreamDetection.test.mjs, 20 cases, one per behaviour the comments record (errors, redirects, CORS preflights, HEAD, pages at a stream's address, a player's text/html manifest, proxies, tracking pixels, redirects to addresses that name nothing, custom patterns). The 272 background tests pass unchanged. background.mjs: -156 lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second step of splitting background.mjs: the 48 top-level declarations of MPV mode - the hand-off (openInMpv, autoOpenInMpv, sendPlayedToMpv, openMpvWithSources), the toggle (startMpv, stopMpv, onToggleMpv, leaveMpvWhenOff, inheritMpv), the autoplay watch over the next episode (mpvWatch, watchMpvFor, its countdown, goToEpisode...), the decoder and error reports, and tabSources (it sets mpvWatch) - moved with their comments by a script that cuts each declaration from the syntax tree, exports it, and writes both modules' imports from the reference graph. Its guards held: no moved variable is assigned outside the move (the LastManualMpv* the message handler sets stay), and no moved initializer reads background.mjs while the modules load, so the import cycle (MpvMode uses background.mjs's state and helpers, which it exports now; background.mjs registers the listeners at its top level, as the event page needs) is safe. Typedefs imported across. background.mjs: 4,724 -> 3,476 lines. The 294 background tests pass unchanged (UrlMatchList.test reads both files now). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
background.mjs was 4,900 lines. Two parts go into modules of their own, without a change in behaviour:
StreamDetection.mjs: how the background classifies each response (classifyResponse→ ignore / subtitles / source with its mode), as pure functions that take the custom-pattern matcher as a parameter. The listener calls it and does the side effects (VpnMirror.noteSource, handleSubtitles, onSourceRecieved) as before. 20 table cases intests/unit/StreamDetection.test.mjs.MpvMode.mjs: MPV mode, 48 declarations (1,267 lines) moved as they were. It imports the state it shares with background.mjs from there; it runs nothing at load that reads those bindings (new UrlMatchList(),new MpvBackend(),Promise.resolve()only), so the cycle is safe.background.mjs: 3,476 lines.
Checks
recoverFrameSources, which passes it; none gone.🤖 Generated with Claude Code