Skip to main content

Crate tauri_plugin_topcoat

Crate tauri_plugin_topcoat 

Source
Expand description

Serve a topcoat application to a Tauri webview over a custom protocol.

No port is bound and no socket is opened. topcoat’s router is already a function from an HTTP request to an HTTP response - Router::handle needs none of its serve feature - so a Tauri custom protocol can call it directly, and the request never leaves the process.

use topcoat::router::Router;

// With topcoat's `discover` feature this is `Router::builder().discover()`.
let plugin = tauri_plugin_topcoat::Builder::new(Router::builder()).build()?;

tauri::Builder::default().plugin(plugin);
// ...then `.run(tauri::generate_context!())` as usual.

Point the window at topcoat://localhost/; Tauri rewrites that to http://topcoat.localhost/ on the platforms that need it.

§What it adds

Two things the webview gets wrong, both measured on macOS by the probe binary here; nobody has run it on the other two yet:

  • One origin. The server always sees https://<scheme>.localhost, whatever URL shape the platform handed the webview.
  • Redirects. No webview follows a Location from a custom protocol, so Post/Redirect/Get is followed here instead.

§What you cannot do

A custom protocol response is one buffered blob, so nothing streams: topcoat’s sse feature, datastar, and any long-lived body have nowhere to go. WebSockets need an HTTP upgrade a protocol handler can’t perform. Compression is dropped on the way in, and cookies don’t survive in either direction.

None of that fails quietly. Use one and you get a 502 naming it, because delivering half a response would have you debugging your application instead of this transport.

Everything else - pages, shards, procedures, forms, assets - goes through untouched.

§Sessions

topcoat puts its session token in a cookie, and WebKit throws away every cookie a custom protocol sets. The session feature fixes that in topcoat’s own TokenStore seam. See Builder::sessions.

§Tracing

The tracing feature reports what this plugin decided, which is the part nothing else can see: a request served and how it ended, a navigation blocked, a response refused and which capability did it, a session handed over or withheld and which rule withheld it. Each request is a serve span naming its webview. Turning it on turns on the transport’s events too.

The token is never reported: no function that reports a session takes one, so it holds by signature.

§Tauri commands

They keep working, with nothing to configure: invoke needs the injected IPC script, and Tauri treats a page on a registered custom protocol as a local origin. An application that sets a strict Content-Security-Policy must allow connect-src ipc: http://ipc.localhost itself.

Structs§

Builder
Builds the plugin.
Origin
A scheme://host origin, compared without regard to ASCII case.
Session
Drives a router exactly as a webview would, without one.

Enums§

Error
Why a plugin could not be built.
OriginError
A protocol scheme that could not be turned into an origin pair.
Platform
The URL shape a webview gives a custom protocol.

Constants§

DEFAULT_SCHEME
The protocol scheme used unless Builder::scheme says otherwise.