package bridge import ( _ "embed" "encoding/json" ) //go:embed bridge.js var bridgeJS string // PageConfig is exposed to the page as window.__yetano_config (and // window.yetano.config) before the bridge installs itself. type PageConfig struct { External string `json:"external"` // "reject" (default) or "passthrough" Transport string `json:"transport"` // "native" (scheme handler) or "inline" (data: entry, bridge only) Origin string `json:"origin,omitempty"` DefaultTimeoutMs int `json:"defaultTimeoutMs,omitempty"` HandshakeTimeoutMs int `json:"handshakeTimeoutMs,omitempty"` ForwardConsole bool `json:"forwardConsole,omitempty"` Selftest bool `json:"selftest,omitempty"` Run int `json:"run,omitempty"` ProtocolOverride int `json:"protocolOverride,omitempty"` // tests only } // InitScript returns the document-start script: config + bridge. func InitScript(cfg PageConfig) string { if cfg.External == "" { cfg.External = "reject" } b, _ := json.Marshal(cfg) return "window.__yetano_config=" + string(b) + ";\n" + bridgeJS }