Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: capture offline compositions in headless Chrome (#9397)

[._.]/ Adam Eivye9976605e7e6
diff --git a/server/services/htmlComposition/browser.js b/server/services/htmlComposition/browser.js
index ca5c8b7687..6b4ba95ee7 100644
--- a/server/services/htmlComposition/browser.js
+++ b/server/services/htmlComposition/browser.js
@@ -96,7 +96,8 @@ export async function openComposition(directory, { signal, validateAssets, strea
signal?.throwIfAborted();
const response = await cdpRequest('/json/version');
if (!response.ok) throw new Error('Managed browser is unavailable');
- const { webSocketDebuggerUrl } = await response.json();
+ const version = await response.json();
+ const { webSocketDebuggerUrl } = version;
if (!webSocketDebuggerUrl) throw new Error('Managed browser has no CDP endpoint');
const ws = new WebSocket(webSocketDebuggerUrl, { handshakeTimeout: 10000 });
const pending = new Map();
@@ -129,6 +130,12 @@ export async function openComposition(directory, { signal, validateAssets, strea
const key = decodeURIComponent(url.pathname);
const asset = url.origin === ORIGIN && !url.username && !url.password && params.request.method === 'GET' && assets.get(key);
if (!asset) {
+ // A foreground headless target may ask for Chrome's implicit favicon.
+ // Answer the absent local icon without allowing any network request.
+ if (url.origin === ORIGIN && !url.username && !url.password && params.request.method === 'GET' && key === '/favicon.ico') {
+ await send('Fetch.fulfillRequest', { requestId: params.requestId, responseCode: 204, body: '' });
+ return;
+ }
// Do not continue even a failed request. Disconnect destroys the context.
throw new Error(`Refused composition request: ${params.request.url}`);
}
@@ -212,7 +219,11 @@ export async function openComposition(directory, { signal, validateAssets, strea
// Defense in depth for browser-originated HTTP requests outside Fetch.
proxyServer: 'http://127.0.0.1:9', proxyBypassList: '<-loopback>',
}, null));
- const { targetId } = await send('Target.createTarget', { url: 'about:blank', browserContextId: contextId, hidden: true, background: true }, null);
+ // Headless Chrome has no tab UI to hide. Give its compositor a foreground
+ // target: hidden targets can stall surface screenshots on Linux. Headed
+ // managed browsers retain the hidden, background rendering posture.
+ const headless = /HeadlessChrome\//.test(version['User-Agent'] || '');
+ const { targetId } = await send('Target.createTarget', { url: 'about:blank', browserContextId: contextId, hidden: !headless, background: !headless }, null);
({ sessionId } = await send('Target.attachToTarget', { targetId, flatten: true }, null));
await send('Page.enable');
await send('Runtime.enable');
diff --git a/server/services/htmlComposition/index.test.js b/server/services/htmlComposition/index.test.js
index b270184f49..788d6ba6ce 100644
--- a/server/services/htmlComposition/index.test.js
+++ b/server/services/htmlComposition/index.test.js
@@ -77,7 +77,7 @@ describe.skipIf(!chrome || !ffmpeg)('HTML composition with real Chrome and ffmpe
afterAll(() => _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots }));
- it('awaits every seek, encodes exactly 12 frames, keeps the target hidden and registers a thumbnail', async () => {
+ it('awaits every seek, encodes exactly 12 frames, disposes its private target and registers a thumbnail', async () => {
const input = await composition();
const before = await browserSession.send('Target.getTargets');
const observed = [];
@@ -102,7 +102,9 @@ describe.skipIf(!chrome || !ffmpeg)('HTML composition with real Chrome and ffmpe
// rather than requiring the browser's unrelated internal targets to freeze.
const extraTargets = (await Promise.all(observed)).flatMap(snapshot => snapshot.targetInfos).filter(info => info.url === 'https://composition.invalid/index.html');
expect(extraTargets.length).toBeGreaterThan(0);
- expect(extraTargets.every(info => info.type === 'other')).toBe(true); // hidden CDP target type
+ // This suite owns a headless browser: its compositor needs a page target,
+ // while headed managed browsers continue using a hidden target.
+ expect(extraTargets.every(info => info.type === 'page')).toBe(true);
const renderContexts = new Set(extraTargets.map(info => info.browserContextId));
expect(before.targetInfos.every(info => !renderContexts.has(info.browserContextId))).toBe(true);
const after = await browserSession.send('Target.getTargets');
@@ -380,7 +382,7 @@ globalThis.portosComposition = { durationSec:1, fps:12, width:1280, height:720,
const onProgress = event => {
if (event.generationId !== input.jobId || closed) return;
closed = browserSession.send('Target.getTargets').then(({ targetInfos }) => {
- const target = targetInfos.find(info => info.type === 'other');
+ const target = targetInfos.find(info => info.url === 'https://composition.invalid/index.html');
return browserSession.send('Target.closeTarget', { targetId: target.targetId });
});
};