Open the devtools console. The following globals are available:
initIPN — the WASM initializerwasmURL — URL to the main.wasm assetcacertURL — URL to the Mozilla CA bundle (PEM)loadCACerts() — fetches and caches the bundle as a stringExample:
const newIPN = await initIPN(wasmURL)
const ipn = newIPN({ authKey: "tskey-auth-...", hostname: "test" })
ipn.run({
notifyState: (s) => console.log("state:", s),
notifyBrowseToURL: (url) => console.log("login:", url),
})
ipn.login()
// State and addresses are getters, not methods:
console.log(ipn.state, ipn.running)
// Once running, try the networking APIs:
const conn = await ipn.dial("tcp", "some-peer:22")
console.log(conn.localAddr, "->", conn.remoteAddr)
const pc = await ipn.listenICMP("icmp4")
const tls = await ipn.dialTLS("some-peer.tail-scale.ts.net:443")
// Use the Mozilla CA bundle to talk to hosts with non-LE certs:
const caCerts = await loadCACerts()
const tls2 = await ipn.dialTLS("example.com:443", { caCerts })
// Accept incoming TCP connections via async iteration:
const ln = await ipn.listen("tcp", "0.0.0.0:8080")
console.log("listening on", ln.addr)
for await (const c of ln) {
console.log("got conn from", c.remoteAddr)
c.close()
}
Loading…