Skip to content

Gemini Canvas Proxy - real streaming and media input

Latest

Choose a tag to compare

@pranrichh pranrichh released this 14 Nov 09:00
· 22 commits to main since this release

An OpenAI-compatible endpoint backed by a Gemini Canvas tab. Canvas runs your
page in a sandboxed iframe and authenticates the calls it makes; this project
carries a request there and back.

What's new

Streaming is real. Responses are forwarded as Gemini produces them instead
of being buffered and replayed as one chunk. The first token arrives when the
model produces it, and the timeout applies between events rather than to the
whole response.

The status means something. The panel reports three links separately — the
page, the extension relay, the native host — each from evidence about that link.
The host counts as connected once it announces itself, and a heartbeat demotes
the relay when it stops answering.

Speech. gemini-2.5-flash-preview-tts and gemini-2.5-pro-preview-tts work
through the same endpoint. Pass voice, get a WAV in message.audio.

Media in. Images, audio, video and PDF: any data URI whose type Gemini
accepts inline, OpenAI input_audio parts, and file parts carrying base64.

The panel. Model name read from the request, tokens split into input and
output, request and response behind toggles, generated images rendered inline,
and a player for speech.

Fixed

  • Chrome passes the calling origin to a native host as a positional argument;
    the parser rejected it, so the host exited on every start.
  • The page handed its port to window.parent, which is not always the page
    holding the relay.
  • Canvas renders the preview more than once; both copies claimed the same port.
  • A frame with no relay answered "not connected" before the frame with the relay
    could answer.
  • Requests routed to a tab with no relay waited out the full timeout.
  • A dropped relay left the page offline for good: the retry fired once and
    stopped instead of starting a new handshake.
  • Several system messages collapsed to the last one; content: null on a
    tool-call turn crashed; parts without a text field raised.
  • Tool results truncated at 5,000 characters without saying so. The limit is
    PROXY_TOOL_RESULT_MAX_CHARS and the marker states the loss.
  • response_format: json_schema now maps to responseSchema.
  • HTTP/1.0 only, HTML 404s, and a /health that reported "disconnected" in
    bare-metal mode, where the connection is stdio.
  • The documented VPS command failed: Compose appends port lists, so the
    all-interfaces bind collided with the loopback one.
  • --start-page is not a Chromium flag; the container never opened Gemini.
  • setup.sh --list modified the install, and setup.ps1 resolved a null
    interpreter when only python3 was present.
  • toggle-vnc.sh never made it into the image, so the documented
    podman exec … toggle-vnc.sh stop failed.
  • setup.sh told you the page would read "native host offline". It reads
    "Host offline".

Removed

--standalone. It printed a banner and returned, which ended the process and
took the HTTP server with it. --http-only covers the case.

Upgrading

  1. Replace extension/ and reload it at chrome://extensions.
  2. Re-paste canvas-proxy.html into the Canvas.
  3. Re-run ./setup.sh (or .\setup.ps1). It rewrites the manifests, the
    interpreter wrapper and the token; clients keep the same port, endpoints and
    bearer token.
  4. Restart the browser, or rebuild the container.

Tests

54 tests, standard library only:

python3 -m unittest discover -s tests -v

Translation, the HTTP surface, streaming, error shapes, chunk reassembly, and
the native messaging protocol against the real binary. CI runs them on Python
3.8 and 3.12 and checks the documentation against the source.

MIT licensed.