mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-09-04 06:55:21 +00:00
fix(extension): control nested players without permission prompts or churn
Google Drive and YummyAnime host their player in a cross-origin iframe. The 3.1.2 targeting work reached those frames but misdiagnosed and destabilized them in four separate ways. No manifest permission is added or restored; webNavigation stays removed. Access diagnosis was inferred, not measured. Every frame probe error was swallowed, and any origin that failed to answer was reported as missing host access. A slow or still-loading player frame therefore produced "Host access required for youtube.googleapis.com" for an origin the extension already held. The resolver now asks permissions.contains() before raising an access error, and treats a granted-but-unresponsive origin as a retry, not a user decision. Probes were unbounded. Every executeScript in the resolver now runs under a timeout, so one unreachable frame can no longer stall an activation, and the retry budget drops from eight passes to three. The chat overlay followed the player into its frame, which rendered it on top of the video and scoped closing and minimizing to that frame. It is now always installed in the tab's top document, with all chat traffic routed to frame 0, while only the playback controller goes into the selected media frame. Nested targets reactivated continuously. Every heartbeat and content event revalidated the target with a full teardown and reinjection, and the media monitor treated ordinary play, pause and buffering as frame layout changes. Both paths now reactivate only when the selected frame or document actually moves. Also restores the audio-route retention that keeps a deselected tab audible: createMediaElementSource() can only be called once per element, so a reinjected content script must adopt the existing route rather than rebuild it. Verified with 90 unit tests, 40 browser E2E tests including two new Drive-shaped fixtures that assert the controller lands in the player frame while the chat stays in the top document, and npm run verify. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -445,3 +445,110 @@ describe('cross-origin media-frame targeting', () => {
|
||||
)).rejects.toMatchObject({ code: MEDIA_FRAME_AMBIGUOUS });
|
||||
});
|
||||
});
|
||||
|
||||
describe('embedded player access diagnosis', () => {
|
||||
function driveTop() {
|
||||
return frame(0, {
|
||||
href: 'https://drive.google.com/file/d/abc/view',
|
||||
origin: 'https://drive.google.com',
|
||||
bestVideo: null,
|
||||
videoCount: 0,
|
||||
embeddedFrames: [{
|
||||
href: 'https://youtube.googleapis.com/embed/abc?origin=https%3A%2F%2Fdrive.google.com',
|
||||
origin: 'https://youtube.googleapis.com',
|
||||
area: 640 * 360,
|
||||
width: 640,
|
||||
height: 360,
|
||||
visible: true,
|
||||
depth: 1,
|
||||
mediaHint: true
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
it('does not demand access for a player origin the extension already holds', async () => {
|
||||
const executeScript = vi.fn().mockResolvedValue([driveTop()]);
|
||||
const contains = vi.fn().mockResolvedValue(true);
|
||||
|
||||
// The player frame never answered the probe, but the grant exists. That
|
||||
// is a loading race, not a user decision, so the tab stays selected on
|
||||
// its top frame instead of raising a permission prompt.
|
||||
await expect(resolveMediaContentTarget(
|
||||
{ scripting: { executeScript }, permissions: { contains } },
|
||||
42,
|
||||
{ attempts: 1, probeDelayMs: 0 }
|
||||
)).resolves.toEqual({
|
||||
frameId: 0,
|
||||
documentId: null,
|
||||
frameUrl: null,
|
||||
hasVideo: false,
|
||||
scriptTarget: { tabId: 42 }
|
||||
});
|
||||
expect(contains).toHaveBeenCalledWith({
|
||||
origins: ['https://youtube.googleapis.com/*']
|
||||
});
|
||||
});
|
||||
|
||||
it('demands access only when the browser confirms the origin is withheld', async () => {
|
||||
const executeScript = vi.fn().mockResolvedValue([driveTop()]);
|
||||
const contains = vi.fn().mockResolvedValue(false);
|
||||
|
||||
await expect(resolveMediaContentTarget(
|
||||
{ scripting: { executeScript }, permissions: { contains } },
|
||||
42,
|
||||
{ attempts: 1, probeDelayMs: 0 }
|
||||
)).rejects.toMatchObject({
|
||||
code: MEDIA_FRAME_ACCESS_REQUIRED,
|
||||
host: 'youtube.googleapis.com'
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps demanding access when the browser cannot answer', async () => {
|
||||
const executeScript = vi.fn().mockResolvedValue([driveTop()]);
|
||||
const contains = vi.fn().mockRejectedValue(new Error('unavailable'));
|
||||
|
||||
await expect(resolveMediaContentTarget(
|
||||
{ scripting: { executeScript }, permissions: { contains } },
|
||||
42,
|
||||
{ attempts: 1, probeDelayMs: 0 }
|
||||
)).rejects.toMatchObject({ code: MEDIA_FRAME_ACCESS_REQUIRED });
|
||||
});
|
||||
|
||||
it('resolves instead of hanging when a frame probe never settles', async () => {
|
||||
const executeScript = vi.fn()
|
||||
.mockImplementationOnce(() => new Promise(() => {}))
|
||||
.mockResolvedValue([frame(0, { bestVideo: null, videoCount: 0 })]);
|
||||
|
||||
await expect(resolveMediaContentTarget(
|
||||
{ scripting: { executeScript } },
|
||||
42,
|
||||
{ attempts: 1, probeDelayMs: 0, probeTimeoutMs: 20 }
|
||||
)).resolves.toMatchObject({ frameId: 0, scriptTarget: { tabId: 42 } });
|
||||
});
|
||||
|
||||
it('prefers a real accessible player over a Drive embed', async () => {
|
||||
const top = frame(0, {
|
||||
href: 'https://drive.google.com/file/d/abc/view',
|
||||
origin: 'https://drive.google.com',
|
||||
bestVideo: video({ controls: true, duration: 2400, renderedArea: 900 * 506 }),
|
||||
embeddedFrames: [{
|
||||
href: 'https://youtube.googleapis.com/embed/abc?origin=https%3A%2F%2Fdrive.google.com',
|
||||
origin: 'https://youtube.googleapis.com',
|
||||
area: 320 * 180,
|
||||
width: 320,
|
||||
height: 180,
|
||||
visible: true,
|
||||
depth: 1,
|
||||
mediaHint: true
|
||||
}]
|
||||
});
|
||||
const executeScript = vi.fn().mockResolvedValue([top]);
|
||||
const contains = vi.fn().mockResolvedValue(false);
|
||||
|
||||
await expect(resolveMediaContentTarget(
|
||||
{ scripting: { executeScript }, permissions: { contains } },
|
||||
42,
|
||||
{ attempts: 1, probeDelayMs: 0 }
|
||||
)).resolves.toMatchObject({ frameId: 0, hasVideo: true });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user