Skip to content

Releases

Gemini Canvas Proxy - real streaming and media input

Choose a tag to compare

@pranrichh pranrichh released this 14 Nov 09:00

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.

Gemini Canvas Proxy — security and reliability pass

Choose a tag to compare

@pranrichh pranrichh released this 06 Aug 13:17

Gemini Canvas Proxy v1.1.0

A security and reliability pass over v1.0.0, plus a documentation rewrite.

Security

  • Bearer-token authentication on every /v1/* route, compared in constant
    time, generated per install, with /health left open so a healthcheck does
    not need the secret.
  • Loopback by default. PROXY_BIND=0.0.0.0 is an explicit opt-in and logs a
    warning when used.
  • CORS off unless PROXY_ALLOWED_ORIGIN names exactly one origin.
  • SSRF defences on remote image URLs: private, loopback, link-local and
    metadata addresses are rejected, the check is reapplied on every redirect, the
    body is capped at 20 MB, and the feature is off unless
    PROXY_ALLOW_URL_FETCH=true.
  • Destination validation in the Canvas page: only
    /v1beta/models/<model>:(generateContent|streamGenerateContent) is accepted,
    and the resolved URL is re-checked against generativelanguage.googleapis.com
    before the fetch.
  • Extension trust boundary: the content script is scoped to
    https://gemini.google.com/*, every runtime message is origin-checked, and
    traffic moves to a private MessageChannel port instead of wildcard
    postMessage broadcasts.
  • Request bodies over 32 MB are refused before they are parsed.

Reliability

  • Docker port race fixed. The entrypoint runs --http-only and owns port
    8765; Chromium launches --bridge-only, which speaks stdio and connects to a
    mode-0600 Unix socket. One process ever binds the port, and requests fail
    fast with 502 when the bridge is absent.
  • MV3 state persisted in chrome.storage.session: the selected Canvas tab
    and partial chunk buffers, the latter with a 90-second TTL sweep.
  • Byte-accurate chunking. Oversized requests are split on encoded UTF-8
    bytes and base64-encoded per envelope, so CJK and emoji payloads survive
    intact and every message stays under the 1 MiB frame limit.
  • Per-call thought signatures. Real Gemini signatures round-trip through
    x_gemini_thought_signature instead of a single placeholder for every call.
  • Blocked responses surface. A safety-blocked or empty Gemini response
    becomes a 502 with blockReason and safetyRatings in error.details
    instead of an empty success.
  • More generation parameters translated: top_k, seed,
    frequency_penalty, presence_penalty, stop as string or list, and
    response_format: json_object. Unsupported options log a warning rather than
    disappearing.
  • Paged status indicator. The Canvas page no longer turns green on a timer;
    it waits for the relay to acknowledge the MessageChannel port.

Cleanup

  • Removed the dead /internal/payload/* endpoint and the stale code around it.
  • Extension IDs are validated as exactly 32 characters from [a-p] everywhere.
  • 15 stdlib tests plus a GitHub Actions workflow, with no third-party
    dependencies.

Docs

  • README rebuilt; reference material split into docs/: architecture, API,
    deployment, security, troubleshooting, integrations, Podman.
  • BrowserSignin=0 / SyncDisabled Chromium policy baked into the image so a
    cookie-only login survives a container restart.
  • Podman quadlet guide and toggle-vnc.sh for hosts that want the browser view
    off most of the time.

Breaking change

Every /v1/* route now requires Authorization: Bearer <token>. The token is
printed by setup.sh / setup.ps1 and stored at native_host/.proxy_token
(/browser-data/proxy-token in Docker). Any client that previously sent no key
has to be updated.

Correction, added in v2.0.0

These notes originally said the status indicator "shows offline when the native
host drops". That was only half true.

The page does wait for a relay acknowledgement now, but that acknowledgement
proves the content script exists — not that the native host is running. With no
manifest installed and no Python process, the page still displayed LIVE.
The offline path also required a disconnect event that frequently never arrived,
because the state broadcast fired before Chrome had started the host and was
dropped if the content script had not yet loaded.

v2.0.0 replaces this with three independently reported links and a heartbeat.
See the v2.0.0 notes.

MIT licensed.

Gemini Canvas Proxy

Choose a tag to compare

@pranrichh pranrichh released this 23 Jun 00:50

Gemini Canvas Proxy

An OpenAI-compatible endpoint backed by a Gemini Canvas tab.

Canvas runs your HTML in a sandboxed iframe and injects a working API key into
it. The proxy puts a page in that iframe, hands a MessageChannel port out to a
browser extension, and lets a local Python process drive it. Point any OpenAI
client at http://127.0.0.1:8765/v1 with the bearer token as the API key and
you get a chat completions endpoint.

How a request travels

your app
  │  POST http://127.0.0.1:8765/v1/chat/completions
  ▼
native host (Python, OpenAI ⇄ Gemini translation)
  │  stdio, 4-byte length + JSON
  ▼
extension service worker
  │  chrome.tabs.sendMessage
  ▼
content script on gemini.google.com
  │  MessageChannel port
  ▼
Canvas page → generativelanguage.googleapis.com

The port is the part that matters. A WebSocket from the Canvas iframe to
localhost is blocked by Chrome's Local Network Access; a transferred port is not
a network request, so it is unaffected.

What works

Capability Status
Chat completions works
Tool and function calling works
Multi-turn conversations works
Image input (data URIs) works
Image generation works
Streaming works, but buffered: one SSE chunk at the end (fixed in v2)
Requests over 1 MB chunked across native messages
Docker Compose, self-contained works

Install

git clone https://github.com/pranrichh/gemini-canvas-proxy.git
cd gemini-canvas-proxy
./setup.sh

Then:

  1. chrome://extensions → Developer mode → Load unpacked → extension/
  2. Copy the extension ID and give it to setup.sh when it asks
  3. gemini.google.com → Canvas → "Create an HTML web app" → paste
    canvas-proxy.html → Preview

Test it with the token setup.sh printed:

export PROXY_TOKEN="$(cat native_host/.proxy_token)"
curl http://127.0.0.1:8765/v1/chat/completions \
  -H "Authorization: Bearer $PROXY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"model":"gemini-3-flash-preview","messages":[{"role":"user","content":"Hello"}]}'

Docker:

docker compose up -d --build
# open http://127.0.0.1:6080/vnc.html, log into Gemini, load /app/extension
docker compose exec proxy /app/setup-extension.sh <extension-id>
docker compose restart proxy

Before you install

  • The Canvas tab must stay open. The credential lives in that page. Close it
    and requests fail.
  • The key is model-scoped. Canvas injects a key valid for whichever model
    that session is promoting. Anything else returns 403.
  • It is not free of strings. Driving a Canvas session from outside the page
    is outside Google's terms of service. Treat this as a personal tool.

Known limitations

  • Streaming is simulated: the response is buffered and replayed as one chunk.
    Tool-call deltas are correct, incremental text is not.
  • n > 1, logprobs and top_logprobs are ignored.
  • The status indicator on the Canvas page trusts the relay ack, so it can show
    "online" while the native host is down. Fixed in v2.
  • One request in flight per Canvas page.

MIT licensed.


v1.0.0, June 2026. The notes above were rewritten in v2.0.0: the original
shipped a curl example with no Authorization header, which returns 401.