Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ function removeContextMenu(id) {
}
});
}
const MAX_VIDEO_ITEMS = 8;

// Host exclusion domains and their predicate are defined once in shared.js.

Expand Down Expand Up @@ -1156,27 +1155,23 @@ function enqueueVideoStateWrite(tabId, write) {

function snapshotVideoFinds(finds) {
const frames = [];
// The menu is capped at eight URLs. Bound persisted data on pages with many
// iframes/videos; retain a blob marker when present to pair with manifests.
let frameCount = 0;
// Persist every active DOM-video report so simultaneous videos survive a
// worker restart. Empty frame reports are omitted; sniffed network URLs
// remain separately bounded to avoid unbounded growth on long-lived tabs.
for (const [frameId, videos] of finds.frames) {
if (frameCount++ >= 32) break;
const out = [];
const seen = new Set();
let hasBlob = false;
for (const video of videos || []) {
if (video && typeof video.src === "string" && video.src && !seen.has(video.src)) {
if (seen.size < MAX_VIDEO_ITEMS) {
seen.add(video.src);
const saved = { src: video.src, blob: video.blob === true };
if (Number.isFinite(video.height) && video.height > 0) saved.height = video.height;
out.push(saved);
}
seen.add(video.src);
const saved = { src: video.src, blob: video.blob === true };
if (Number.isFinite(video.height) && video.height > 0) saved.height = video.height;
out.push(saved);
} else if (video && video.blob === true && !hasBlob) {
hasBlob = true;
out.push({ src: null, blob: true });
}
if (out.length >= MAX_VIDEO_ITEMS + 1) break;
}
if (out.length) frames.push([frameId, out]);
}
Expand Down Expand Up @@ -1288,9 +1283,7 @@ function domVideosFor(tabId) {

function mergedVideoUrls(tabId) {
const f = videoFinds.get(tabId);
return f
? mergeVideoFinds(domVideosFor(tabId), f.sniffed, f.kinds).slice(0, MAX_VIDEO_ITEMS)
: [];
return f ? mergeVideoFinds(domVideosFor(tabId), f.sniffed, f.kinds) : [];
}

function sniffedHeader(headers, name) {
Expand Down
36 changes: 36 additions & 0 deletions test/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,42 @@ describe("detection wiring", () => {
);
});

test("all simultaneously playing videos appear beyond the old eight-item cap", async () => {
const chrome = makeChrome();
loadBackground(chrome);
const L = chrome._listeners;
const tabId = 12;

await L["tabs.onActivated"]({ tabId });
L["runtime.onMessage"](
{
type: "grab-videos-detected",
videos: Array.from({ length: 10 }, (_, i) => ({
src: "https://cdn.example.com/v/video-" + i + ".mp4",
blob: false,
})),
},
{ tab: { id: tabId, url: "https://example.com/" }, frameId: 0 }
);
await tick();

const itemIds = [
...new Set(
chrome._calls
.filter(([name, id]) => name === "menus.create" && /^grabVideo:\d+$/.test(String(id)))
.map(([, id]) => id)
),
];
assert.deepEqual(
itemIds,
Array.from({ length: 10 }, (_, i) => "grabVideo:" + i),
"every distinct actively playing video gets a menu entry"
);

const saved = chrome._session.get("videoFinds:" + tabId);
assert.equal(saved.frames[0][1].length, 10, "all active videos survive worker persistence");
});

test("a blob: video is paired with the tab's sniffed manifest", async () => {
const chrome = makeChrome();
loadBackground(chrome);
Expand Down
Loading