import assert from 'node:assert/strict'; // Exercise the actual standalone Electron child in the existing hidden application, never native PiP. export async function checkStreamPopout({ app, page, check, screenshot }) { const cdp = await page.context().newCDPSession(page); const id = 'stage-mira'; const selector = `[data-stream-id="${id}"]`; const baseline = await cdp.send('Runtime.evaluate', { expression: `(() => { const video = document.querySelector('section.stream-view[data-stream-id="stage-mira"] video'); if (!video?.srcObject) throw new Error('Popout baseline requires attached media'); window.__popoutOriginal = { video, media: video.srcObject }; return { joins: window.__joins, watch: window.teamspeachDiagnostics.snapshot().watches.find(w => w.connectionId === 'c1' && w.id === 'stage-mira') }; })()`, returnByValue: true }); if (baseline.exceptionDetails) throw new Error(JSON.stringify(baseline.exceptionDetails)); const before = baseline.result.value; const opened = app.waitForEvent('window'); const activation = await cdp.send('Runtime.evaluate', { expression: `document.querySelector(${JSON.stringify(selector+' [data-role="stream-popout"]')}).click()`, userGesture: true }); if (activation.exceptionDetails) throw new Error(JSON.stringify(activation.exceptionDetails)); let child; try { child = await opened; } catch (error) { const diagnostic = await page.evaluate(() => ({ message: document.querySelector('[data-role="stream-fullscreen-error"]')?.textContent, activation: navigator.userActivation.isActive })); diagnostic.windows = await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows().map(w => ({ url: w.webContents.getURL(), visible: w.isVisible(), offscreen: w.webContents.isOffscreen() }))); throw new Error(`${error.message}: ${JSON.stringify(diagnostic)}`); } await child.waitForURL('**/stream-popout.html'); await child.waitForSelector(selector, { state: 'attached' }); const geometry = await child.evaluate(() => ({ viewport: [innerWidth, innerHeight], nodes: ['html','body','#stream-popout-host','section.stream-view','video'].map(selector => { const node = document.querySelector(selector), style = node && getComputedStyle(node); return { selector, hidden: node?.hidden, rect: node?.getBoundingClientRect().toJSON(), inline: node?.style.cssText, display: style?.display, visibility: style?.visibility, width: style?.width, height: style?.height }; }), sheets: [...document.styleSheets].map(sheet => ({ href: sheet.href, rules: (() => { try { return sheet.cssRules.length; } catch (error) { return error.message; } })() })) })); let childCdp; if (geometry.viewport[0] === 0 || geometry.viewport[1] === 0) { // Electron 44.9.3 guest OSR leaves native viewport 0x0. Explicitly authorized renderer-only // emulation exercises adoption/media; it is NOT unmodified native popout painting evidence. childCdp = await child.context().newCDPSession(child); await childCdp.send('Emulation.setDeviceMetricsOverride', { width: 960, height: 600, deviceScaleFactor: 1, mobile: false }); check(true, 'Detached renderer uses authorized test-only CDP viewport; native OSR painting remains unverified', { native: geometry, emulatedViewport: [960, 600], nativePaintingVerified: false }); } else check(true, 'Detached stream has a native painted viewport', geometry); await child.waitForSelector(selector); const safety = await app.evaluate(({ BrowserWindow }) => { const w = BrowserWindow.getAllWindows().find(w => w.webContents.getURL().includes('/stream-popout.html')); return { visible: w.isVisible(), focused: w.isFocused(), focusable: w.isFocusable(), offscreen: w.webContents.isOffscreen(), muted: w.webContents.isAudioMuted(), preload: w.webContents.getLastWebPreferences().preload ?? null }; }); assert.deepEqual(safety, { visible: false, focused: false, focusable: false, offscreen: true, muted: true, preload: null }); assert.deepEqual(await child.evaluate(() => ({ bridge: typeof window.teamspeach, require: typeof window.require })), { bridge: 'undefined', require: 'undefined' }); await page.waitForFunction(previous => { const current = window.teamspeachDiagnostics.snapshot().watches.find(w => w.connectionId === 'c1' && w.id === previous.id); return current.framesDecoded > previous.framesDecoded && current.inboundAudioPackets > previous.inboundAudioPackets; }, before.watch); const adopted = await cdp.send('Runtime.evaluate', { expression: 'window.__popoutOriginal.video.ownerDocument !== document && window.__popoutOriginal.video.srcObject === window.__popoutOriginal.media && window.__joins === 2', returnByValue: true }); check(adopted.result.value, 'Standalone hidden child adopts the same video/media while real RTP continues', safety); await screenshot('stream-standalone-popout', child); await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows().find(w => w.webContents.getURL().includes('/stream-popout.html')).close()); await page.waitForSelector(selector); const restored = await cdp.send('Runtime.evaluate', { expression: 'window.__popoutOriginal.video.ownerDocument === document && window.__popoutOriginal.video.srcObject === window.__popoutOriginal.media', returnByValue: true }); check(restored.result.value, 'Closing standalone child restores same video/media without resubscribe'); if (childCdp) await childCdp.detach().catch(() => {}); await cdp.detach(); }