Repository navigation
A reload of the page keeps the buffer for 20 s, in RAM and on the disk - #605
Merged
Merged
Conversation
…he disk His wish (2026-10-28): reloading a page must not throw away what was buffered; what nobody takes back is let go of 20 s later, in RAM and on the disk alike. - At the player's beforeunload, before destroy(), the client hands its finished video files to the background (BUFFER_STASH): RAM ones as their Blobs (shared, not copied: 256 MB sent in 1 ms, measured), disk ones as their OPFS file names and the session directory. No playlist or manifest (old signatures, a live one moves on), no key, nothing in the Cache API or IndexedDB. - chrome/background/BufferStash.mjs keeps a hand-off BufferKeepMs (20 s) under its page, source, private-or-not and container, then lets its Blobs go and deletes its directory. The page is the one BUFFER_TAKE told the player: by the hand-off the tab's frames are the next page's already (measured: an empty address, a new frame object). - The next player of that video on that page takes it back in setSourceInternal, after the reset, before the player is built: the answer structuredClone()d into its realm (its Blobs were no instanceof Blob there, measured), RAM Blobs into its FSBlob (its budget), disk files moved into its own session a few at a time while it starts (FileSystemFileHandle.move, 4 ms for 1 MB), then the old directory deleted. - A new signed link (vidmoly's ?t=&s= at every load): LinkSignature names the parameters the two links differ in, and DownloadManager.stored finds a file under the new link with those left out (an alias: the data stays under its store id, entry.blobId). FreshLink uses the same (relink): a fresh link no longer downloads everything again. Measured in Firefox 159 (ext-specs/reload-keeps-buffer.e2e.mjs): RAM 42 of 42 taken back, 0 asked for again; disk (RAM budget 0, files on the disk) 100 of 100 taken back, 0 asked for again, played from them, the old directory deleted; not taken within 20 s: kept at 5 s, everything downloaded again and the directory gone at 22 s. fresh-link.e2e: 19 downloaded under the old link, 0 asked for again under the fresh one. 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.
Your wish from the upstream triage (#488/#487, reshaped): "if a buffer is loaded and the page reloads, the buffered stuff stays for like 20 seconds, and then gets flushed out of memory. And if the disk is used, the same applies."
What happens now
beforeunloadit hands its finished video files to the background:It also works when the site signs every page load anew (vidmoly's
?t=&s=). The query parameters that differ between the old and the new link are the signature, and a piece matches with those left out. Parameters that didn't change (?n=5) still tell pieces apart. A page check keeps two videos on the same address (hls.php?v=1/?v=2) from ever taking each other's pieces.FreshLink gets the same matching (
DownloadManager.relink). A fresh link after a refusal no longer downloads everything again.Measured in Firefox 159 (new
ext-specs/reload-keeps-buffer.e2e.mjs)fresh-link.e2e)Found while building, measured each time
runtime.getBackgroundPage()doesn't exist in a player iframe inside a web page. So the hand-over goes through messaging. Messages and ports still go out atbeforeunloadandpagehidewhile that page reloads.BUFFER_TAKEanswer, and the player names it in its hand-over.instanceof Blobin the player, so none was taken. The answer is nowstructuredCloned into the player's realm, which shares the data and doesn't copy it.FileSystemFileHandle.move()works on the main thread for OPFS: 4 ms for 1 MB.Tests
LinkSignature(7)BufferStash(5)DownloadManagerHandOff(11), including a second reload in a row, twins under two signatures, and a disk file the player asked for before its movebackgroundBufferStash(4): keys, the page frame reset before the hand-over, a non-player senderkeepStorageOnce+relink; the stand-in player in the "stayed" tests gothandOffBuffer.fresh-link.e2e.Docs
README ("RAM and disk") gets one paragraph;
docs/notes/storage.mdgets a dated section with every measurement above.🤖 Generated with Claude Code