Files
pastilhasandClaude Opus 5 52934f52dc browser, extracted from the platform — extension, relay and all
Your own Chrome, driven from Officer. Not a headless one: it attaches to the browser you are already
signed into, which is the whole difference from /scrape, and /scrape stays behind in the platform.

The relay is a sidecar now, and that is the point. It was a second Bun.serve inside the platform
process on its own port, which is exactly why it was switched off on 2026-08-13 — "the platform serves
one port". A sidecar is a process allowed its own listeners, so the objection stops applying instead of
being argued with.

The boundary across it is deliberately small: two questions, who is connected and what tabs they have,
because only those live in memory on the relay side. Screenshots, evaluation and navigation still go
straight down cdp.ts's own WebSocket to the relay's /cdp endpoint, exactly as before — routing page
bytes through the platform would be work for nothing.

Three normally-breaking changes taken now because now they are free, each already recommended in a
comment by whoever switched the relay off. Its own signing key instead of borrowing getKey('jwt'). Its
own table instead of the platform's user_integrations. And the port kept at 18792 on purpose, because
the port is an input to the token HMAC as well as an address — moving it fails every pairing silently,
and the extension blames the address. user_integrations held zero browser-relay rows, checked in
Postgres rather than assumed, so there was nothing to unpair.

The screen became panels. BrowserScreen.tsx rendered TabList and TabPreview through appType: null
placeholders; both components were already self-contained and took no props, so the screen had nothing
to pass and simply went.

Not tested end to end — no browser has been paired since the move, and that needs a Chrome and a
person. BLOCKERS.md says so rather than the commit implying otherwise.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 01:04:09 +00:00

73 lines
2.8 KiB
TypeScript

import { API_URL } from '@@/officer-url.mjs';
import { createSidecarConnector } from '@@/sidecar/connect';
import { startBrowserRelay, stopBrowserRelay, getUserRelayStatus, getUserTargets, getRelayPort } from './relay';
import { registerUserToken, unregisterUserToken, deriveRelayToken } from './relay-auth';
import { BROWSER_SIDECAR_KIND, RELAY_PORT, type BrowserCommand, type BrowserEvent } from './protocol';
// The browser relay, as its own process.
//
// It was a second `Bun.serve` inside the platform, on its own port, and that is exactly why it was
// switched off on 2026-08-13 — "the platform serves one port". A sidecar is the shape that objection
// asks for, and it is what this is now.
//
// Two listeners live here: the extension's WebSocket (RELAY_PORT, fixed — see protocol.ts) and the
// registration socket back to the platform, which is how `api/router.ts` asks it anything.
type ReplyFn = (msg: BrowserEvent) => void;
async function handleCommand(cmd: BrowserCommand, reply: ReplyFn): Promise<void> {
try {
switch (cmd.type) {
case 'ping':
return reply({ type: 'pong', id: cmd.id });
case 'relay:status': {
const status = getUserRelayStatus(cmd.userId);
return reply({ type: 'relay:status', id: cmd.id, ...status });
}
case 'relay:targets':
return reply({ type: 'relay:targets', id: cmd.id, targets: getUserTargets(cmd.userId) });
case 'relay:token-add': {
// Derived here rather than sent over the wire: the key lives in this process, and a token that
// crossed the boundary would be a credential in a log the moment anything traced these messages.
const token = registerUserToken(cmd.userId, getRelayPort(), cmd.salt);
return reply({ type: 'relay:token', id: cmd.id, token, port: getRelayPort() });
}
case 'relay:token-remove': {
unregisterUserToken(deriveRelayToken(cmd.userId, getRelayPort(), cmd.salt));
return reply({ type: 'relay:ok', id: cmd.id });
}
default:
return reply({ type: 'error', id: (cmd as { id: string }).id, error: `unknown command` });
}
} catch (err) {
reply({ type: 'error', id: cmd.id, error: err instanceof Error ? err.message : String(err) });
}
}
await startBrowserRelay(RELAY_PORT);
console.log(`[browser-relay] listening for extensions on ${RELAY_PORT}`);
const connection = createSidecarConnector({
apiUrl: `${API_URL}/api/sidecar/register`,
name: 'browser-relay',
handles: [BROWSER_SIDECAR_KIND],
onCommand(cmd, reply) {
void handleCommand(cmd as BrowserCommand, reply as ReplyFn);
},
});
function shutdown(signal: string) {
console.log(`[browser-relay] ${signal} received, closing`);
stopBrowserRelay();
connection.destroy();
process.exit(0);
}
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));