mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-18 15:23:13 +00:00
feat: rank player candidates by ordered signals, add browser E2E suite
The weighted score summed incomparable units, so size could outvote traits that disqualify an element outright. Measured on a real page: a display:none preload reports its full 1080p intrinsic size and scored 2073600, beating a visible unmuted player at 509920. Selection now compares an ordered list of signals, highest priority first: has a source, is rendered, is not a silent background loop, rendered size bucket, is playing, has controls, duration. Rendered size replaces intrinsic resolution, and mute state is gone from the ranking entirely: it is a viewer preference, not evidence about which element is the player. It stays a ranking rather than a filter, so a page of only bad candidates still yields one and findVideo never returns null where a video exists. The new tests/e2e suite runs the shipped finder against real fixture pages and drives the packed extension for injection, reinjection and remote play/pause/seek into a first-party frame. All five scoring scenarios fail against the previous implementation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -61,7 +61,33 @@ const fakeDocument = {
|
||||
}
|
||||
};
|
||||
|
||||
const fnSource = extractFunction('findVideo', source);
|
||||
// findVideo delegates to a small set of ranking helpers; they have to be lifted
|
||||
// together or this would silently test a stale shape of the finder.
|
||||
const VIDEO_FINDER_PARTS = [
|
||||
'findVideo',
|
||||
'collectVideoCandidates',
|
||||
'getRenderedVideoArea',
|
||||
'getVideoSizeBucket',
|
||||
'isVideoRendered',
|
||||
'hasPlayableVideoSource',
|
||||
'isBackgroundVideo',
|
||||
'isVideoPlaying',
|
||||
'compareVideoRanks',
|
||||
'pickBestVideo'
|
||||
];
|
||||
|
||||
function extractRankingTable(text) {
|
||||
const start = text.indexOf('const VIDEO_RANKING_SIGNALS');
|
||||
assert.notStrictEqual(start, -1, 'VIDEO_RANKING_SIGNALS not found');
|
||||
const end = text.indexOf('];', start);
|
||||
assert.notStrictEqual(end, -1, 'VIDEO_RANKING_SIGNALS did not terminate');
|
||||
return text.slice(start, end + 2);
|
||||
}
|
||||
|
||||
const fnSource = [
|
||||
...VIDEO_FINDER_PARTS.map(name => extractFunction(name, source)),
|
||||
extractRankingTable(source)
|
||||
].join('\n');
|
||||
const findVideo = Function('document', `${fnSource}; return findVideo;`)(fakeDocument);
|
||||
|
||||
const selected = findVideo(fakeDocument);
|
||||
|
||||
Reference in New Issue
Block a user