Browser Support Test — Go source
Audit your real browser against 30 modern web capabilities - WebGPU, WASM, WebAuthn, Service Workers and more. Get a weighted readiness score, copy-paste detection snippets, and a shareable link.
This is the Go implementation — the same logic the interactive tool runs, in a shareable, citable form.
// Browser Support Test — runtime capability probe, weighted score, tier.
//
// Language: Go
// CosmoDev polyglot showcase port of the `browser-support-test` tool.
// Ported from src/tools/BrowserSupportTest.tsx (+ browser-support/* modules) —
// display source, part of CosmoDev's polyglot tool pages.
//
// ILLUSTRATIVE PORT: the live tool detects *browser* features at runtime
// (navigator/window probes) — a browser-only concern that cannot run in Go.
// This port shows the ANALOGOUS pattern for a Go process: it reads
// runtime.Version() and resolves a matrix of stdlib capabilities gated on the
// Go language version (the mechanism Go uses to gate new features). The
// scoring algorithm and tier thresholds below are byte-for-byte the same as
// the TypeScript lib's; only the probe targets differ.
package main
import (
"fmt"
"runtime"
"strconv"
"strings"
)
type status string
const (
stSupported status = "supported"
stUnsupp status = "unsupported"
stUnknown status = "unknown"
)
// contribution × weight. Same values as src/tools/browser-support/score.ts.
func contribution(s status) float64 {
switch s {
case stSupported:
return 1
case "limited":
return 0.5
case "needs-https":
return 0.3
default: // unsupported, unknown
return 0
}
}
type check struct {
id, title, category, addedIn string
weight float64
}
type result struct {
id string
status status
}
// Weighted readiness 0–100; matches computeScore() exactly.
func computeScore(results []result, checks []check) int {
wm := make(map[string]float64, len(checks))
for _, c := range checks {
wm[c.id] = c.weight
}
var earned, possible float64
for _, r := range results {
if w, ok := wm[r.id]; ok {
earned += contribution(r.status) * w
possible += w
}
}
if possible == 0 {
return 0
}
return int((earned/possible)*100 + 0.5)
}
// tierFor mirrors tierFor() in the island — same thresholds.
func tierFor(score int) string {
for _, t := range [...]struct {
min int
label string
}{
{90, "Fully modern"}, {75, "Very capable"}, {55, "Capable, minor gaps"},
{35, "Showing its age"},
} {
if score >= t.min {
return t.label
}
}
return "Legacy browser"
}
// goVersion parses runtime.Version() ("go1.22.3") into (1, 22).
func goVersion() (int, int) {
parts := strings.Split(strings.TrimPrefix(runtime.Version(), "go"), ".")
if len(parts) < 2 {
return 0, 0
}
maj, _ := strconv.Atoi(parts[0])
min, _ := strconv.Atoi(parts[1])
return maj, min
}
// Representative catalog — Go version-gated stdlib capabilities. A probe is
// "supported" when the running Go is >= the version that introduced it.
var checks = []check{
{"errors-join", "errors.Join", "Stdlib", "1.20", 2},
{"log-slog", "log/slog", "Stdlib", "1.21", 3},
{"slices", "slices package", "Stdlib", "1.21", 3},
{"maps", "maps package", "Stdlib", "1.21", 2},
{"context-afterfunc", "context.AfterFunc", "Runtime", "1.21", 2},
{"range-over-int", "range over int", "Language", "1.22", 2},
{"crypto-sha3", "crypto/sha3", "Crypto", "1.22", 3},
{"weak-pkg", "weak package", "Runtime", "1.24", 1},
}
// ge reports whether (maj,min) >= the "major.minor" in `added`.
func ge(maj, min int, added string) bool {
p := strings.Split(added, ".")
if len(p) < 2 {
return false
}
am, _ := strconv.Atoi(p[0])
an, _ := strconv.Atoi(p[1])
return maj > am || (maj == am && min >= an)
}
// runChecks probes the catalog; a panic degrades to 'unknown'.
func runChecks(cs []check) []result {
maj, min := goVersion()
out := make([]result, len(cs))
for i, c := range cs {
func() {
defer func() { recover() }()
if ge(maj, min, c.addedIn) {
out[i] = result{c.id, stSupported}
return
}
out[i] = result{c.id, stUnsupp}
}()
}
return out
}
func main() {
maj, min := goVersion()
rs := runChecks(checks)
score := computeScore(rs, checks)
supported := 0
for _, r := range rs {
if r.status == stSupported {
supported++
}
}
fmt.Printf("Go %d.%d on %s/%s\n", maj, min, runtime.GOOS, runtime.GOARCH)
fmt.Printf("%d/%d capabilities · readiness %d · %s\n",
supported, len(rs), score, tierFor(score))
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →