I built a Go headless browser that retrieves and runs JavaScript with live DOM updates. Test snippet demonstrates a simple HTTP mux serving HTML and JS; HTMX improvements planned.
It("executes remote JS", func() {
muxRouter := http.NewServeMux()
muxRouter.HandleFunc("/home", func(resp http.ResponseWriter, req *http.Request) {
resp.Write([]byte("<html><head><script src=\"/assets/main.js\"></script></head><body>Demo</body></html>"))
})
muxRouter.HandleFunc("/assets/main.js", func(resp http.ResponseWriter, req *http.Request) {
resp.Header().Set("Content-Type", "application/javascript")
resp.Write([]byte("window.flag = true"))
})
browser := newHeadlessBrowser(muxRouter)
Expect(browser.LoadPage("/home")).Error().ToNot(HaveOccurred())
Expect(runScript("window.flag")).To(BeTrue())
})