Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

Make the server's page open over plain HTTP on a private address (#142)

Daniel Carvalho3127e7dc2a4f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcd0c0d..40a2ca4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,11 +7,13 @@ What changed in each version of Tucano. The format follows [Keep a Changelog](ht
> **Em português:**
> - **Conversas longas não pesam mais enquanto um agente responde.** Cada palavra recebida redesenhava todas as mensagens; agora só a que mudou.
> - **O navegador dos agentes abre páginas num servidor Linux que é um PC.** O Chrome esperava o chaveiro bloqueado da área de trabalho e nenhuma página carregava; no servidor ele agora usa o próprio armazenamento.
+> - **A página do servidor abre por HTTP num endereço privado,** como o Tailscale ou a rede de casa. Ela ficava em branco.
### Fixed
- **Long conversations stay light while an agent replies.** Each streamed word redrew and re-parsed every message in the list, keeping the window busy on long conversations. Now only the message that changed is drawn again.
- **An agent's browser loads pages on a Linux server that is a desktop PC.** Chrome waited for the desktop's locked keyring before its first page and never got it, so every page hung. On a server it now uses its own cookie store; a desktop keeps the keyring.
+- **The server's page opens over plain HTTP on a private address,** such as Tailscale or a home network. It stayed blank: a browser outside a secure context has no `crypto.randomUUID`, which the app calls as it starts. The page now brings a small replacement for it, and one for the copy buttons.
## [0.2.11] - 2026-11-05
diff --git a/src/server/index.ts b/src/server/index.ts
index 44c7aa7..74493b0 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -15,6 +15,7 @@ import { extname, join, normalize, sep } from 'node:path'
import { pathToFileURL } from 'node:url'
import { Forwarder, isPrivate } from './forward'
import { vault } from './vault'
+import { INSECURE_CONTEXT_SHIM } from './web-shim'
const dataDir = process.env['TUCANO_DATA'] || join(homedir(), '.tucano-server')
const host = process.env['TUCANO_HOST'] || '127.0.0.1'
@@ -207,7 +208,7 @@ const server = createServer((req, res) => {
// window.tucano for a browser: the core's port comes from the event stream and
// the requests go up by POST; what only the desktop does is left out quietly.
-const WEB = `(() => {
+const WEB = `${INSECURE_CONTEXT_SHIM}(() => {
window.__TUCANO_WEB__ = true
let client = null
const connect = () => {
diff --git a/src/server/web-shim.ts b/src/server/web-shim.ts
new file mode 100644
index 0000000..97a4389
--- /dev/null
+++ b/src/server/web-shim.ts
@@ -0,0 +1,31 @@
+// What a browser keeps from a page that isn't a secure context. Over plain HTTP on a private
+// address (Tailscale, a home network) it has no crypto.randomUUID and no navigator.clipboard, which
+// only HTTPS and localhost get; the app calls the first as it starts, so without this the page
+// stays blank. This is plain JS for the page, run before the app, so it keeps to old syntax.
+export const INSECURE_CONTEXT_SHIM = `(() => {
+ if (typeof crypto.randomUUID !== 'function') {
+ crypto.randomUUID = () => {
+ const b = crypto.getRandomValues(new Uint8Array(16))
+ b[6] = (b[6] & 15) | 64
+ b[8] = (b[8] & 63) | 128
+ const h = Array.prototype.map.call(b, (x) => (x + 256).toString(16).slice(1)).join('')
+ return h.slice(0, 8) + '-' + h.slice(8, 12) + '-' + h.slice(12, 16) + '-' + h.slice(16, 20) + '-' + h.slice(20)
+ }
+ }
+ if (!navigator.clipboard) {
+ const writeText = (text) =>
+ new Promise((resolve, reject) => {
+ const area = document.createElement('textarea')
+ area.value = text
+ area.setAttribute('readonly', '')
+ area.style.cssText = 'position:fixed;top:0;left:0;opacity:0'
+ document.body.appendChild(area)
+ area.select()
+ const ok = document.execCommand('copy')
+ document.body.removeChild(area)
+ ok ? resolve() : reject(new Error('copy not allowed'))
+ })
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
+ }
+})();
+`
diff --git a/test/web-shim.test.ts b/test/web-shim.test.ts
new file mode 100644
index 0000000..24284d3
--- /dev/null
+++ b/test/web-shim.test.ts
@@ -0,0 +1,61 @@
+import { describe, expect, it } from 'vitest'
+import { INSECURE_CONTEXT_SHIM } from '../src/server/web-shim'
+
+// Runs the page's shim against a stand-in browser that is not a secure context: no
+// crypto.randomUUID, no navigator.clipboard.
+function insecure(copied: { ok: boolean } = { ok: true }): { crypto: Record<string, unknown>; navigator: Record<string, unknown>; texts: string[] } {
+ const texts: string[] = []
+ const crypto = { getRandomValues: (a: Uint8Array) => (a.forEach((_, i) => (a[i] = (i * 37 + 11) & 255)), a) } as Record<string, unknown>
+ const navigator: Record<string, unknown> = {}
+ const document = {
+ createElement: () => ({ setAttribute() {}, style: {}, value: '', select() {} }),
+ body: { appendChild: (e: { value: string }) => texts.push(e.value), removeChild() {} },
+ execCommand: () => copied.ok
+ }
+ new Function('crypto', 'navigator', 'document', 'Uint8Array', INSECURE_CONTEXT_SHIM)(crypto, navigator, document, Uint8Array)
+ return { crypto, navigator, texts }
+}
+
+describe('the page shim for a browser outside a secure context', () => {
+ it('can be followed by another script that starts with a parenthesis', () => {
+ const ran: string[] = []
+ const crypto = { randomUUID: () => 'x', getRandomValues: (a: Uint8Array) => a }
+ new Function('crypto', 'navigator', 'document', 'Uint8Array', 'ran', `${INSECURE_CONTEXT_SHIM}(() => { ran.push('next') })()`)(crypto, { clipboard: {} }, {}, Uint8Array, ran)
+ expect(ran).toEqual(['next'])
+ })
+
+ it('gives crypto.randomUUID, as a version 4 UUID', () => {
+ const { crypto } = insecure()
+ const id = (crypto['randomUUID'] as () => string)()
+ expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
+ })
+
+ it('gives different ids when the random bytes differ', () => {
+ let n = 0
+ const crypto = { getRandomValues: (a: Uint8Array) => (a.forEach((_, i) => (a[i] = (i + ++n) & 255)), a) } as Record<string, unknown>
+ new Function('crypto', 'navigator', 'document', 'Uint8Array', INSECURE_CONTEXT_SHIM)(crypto, {}, {}, Uint8Array)
+ const f = crypto['randomUUID'] as () => string
+ expect(f()).not.toBe(f())
+ })
+
+ it('leaves the browser’s own randomUUID and clipboard alone', () => {
+ const own = () => 'own'
+ const clipboard = { writeText: () => Promise.resolve() }
+ const crypto = { randomUUID: own, getRandomValues: (a: Uint8Array) => a } as Record<string, unknown>
+ const navigator: Record<string, unknown> = { clipboard }
+ new Function('crypto', 'navigator', 'document', 'Uint8Array', INSECURE_CONTEXT_SHIM)(crypto, navigator, {}, Uint8Array)
+ expect(crypto['randomUUID']).toBe(own)
+ expect(navigator['clipboard']).toBe(clipboard)
+ })
+
+ it('copies text through a textarea when there is no clipboard', async () => {
+ const { navigator, texts } = insecure()
+ await (navigator['clipboard'] as { writeText: (t: string) => Promise<void> }).writeText('hello')
+ expect(texts).toEqual(['hello'])
+ })
+
+ it('says so when the browser refuses the copy', async () => {
+ const { navigator } = insecure({ ok: false })
+ await expect((navigator['clipboard'] as { writeText: (t: string) => Promise<void> }).writeText('x')).rejects.toThrow()
+ })
+})