From a13c25042799a240f6b36165f5f87307f8469a53 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Sat, 27 Jun 2026 11:12:09 +0200 Subject: [PATCH] Remove static-host header shim --- README.md | 13 +++---- browser_e2e_test.go | 72 --------------------------------------- example/enable-threads.js | 65 ----------------------------------- example/index.html | 2 -- 4 files changed, 5 insertions(+), 147 deletions(-) delete mode 100644 example/enable-threads.js diff --git a/README.md b/README.md index fc2bbd8..b5a7b85 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Go App (WASM) - `Cross-Origin-Opener-Policy: same-origin` - `Cross-Origin-Embedder-Policy: require-corp` or `credentialless` -The example includes `enable-threads.js`, a service worker that adds these headers for static hosts such as GitHub Pages. +The example must be served by a host that sets these headers on the page and runtime assets. ## Installation @@ -271,7 +271,6 @@ Then open `http://localhost:8081`. The example uses: - `example/index.html` -- `example/enable-threads.js` for static-host cross-origin isolation - `example/main.go` for the Go WASM app - `example/migrations/` with `golang-migrate` - generated `database/sql` query code in `example/generated/` @@ -363,14 +362,13 @@ make clean # Remove build artifacts `make fetch-assets` reads the official SQLite download metadata and fetches the current `sqlite-wasm-*.zip` bundle with SHA3 verification. To pin a specific archive, pass `SQLITE_URL` and `EXPECTED_SHA`; `SQLITE_VERSION=3530100 make fetch-assets` selects that version when it is still listed on the download page. -Browser tests build a WASM test binary, serve the SQLite assets with the required headers, launch headless Chrome, and verify OPFS persistence, BLOBs, dump/load, transactions, memory mode, migrations, generated SQL shapes, cancellation, named parameters, browser-context storage behavior, and the static Pages-style example path. CI runs these browser tests on every push and pull request. +Browser tests build a WASM test binary, serve the SQLite assets with the required headers, launch headless Chrome, and verify OPFS persistence, BLOBs, dump/load, transactions, memory mode, migrations, generated SQL shapes, cancellation, named parameters, browser-context storage behavior, and the example path. CI runs these browser tests on every push and pull request. ## GitHub Pages The Pages workflow runs `make build-example` and publishes `./example`. The published directory must contain: - `index.html` -- `enable-threads.js` - `_headers` - `main.wasm` - `wasm_exec.js` @@ -380,7 +378,7 @@ The Pages workflow runs `make build-example` and publishes `./example`. The publ - `sqlite3.wasm` - `sqlite3-opfs-async-proxy.js` -`enable-threads.js` is loaded before the Go WASM app. On static hosts without COOP/COEP response headers, it registers a service worker, reloads the page, and makes the page cross-origin isolated so OPFS can work. +GitHub Pages does not apply `_headers`, so this workflow is only useful as a static artifact publisher. The public `lightning.community` route must add the required headers before serving these files. ## Deployment @@ -398,13 +396,12 @@ Cross-Origin-Resource-Policy: same-origin It must also serve `*.wasm` as `application/wasm`. The repository keeps `example/_headers` for static hosts that understand that file format, but GitHub Pages does not apply `_headers`; the `lightning.community` route should -therefore terminate on a header-capable edge/proxy or the reusable Lightning -Labs WASM static server. +therefore terminate on a header-capable edge/proxy. If the route is proxied through Cloudflare, avoid TLS/proxy settings that make the origin redirect back to the same HTTPS URL. A same-location `301` on `/go-wasmsqlite/` happens before the app loads, so it cannot be fixed by the -service-worker header shim. +demo code. ## Limitations diff --git a/browser_e2e_test.go b/browser_e2e_test.go index ef06ec2..396133e 100644 --- a/browser_e2e_test.go +++ b/browser_e2e_test.go @@ -139,78 +139,6 @@ func TestBrowserE2EExampleSmoke(t *testing.T) { } } -func TestBrowserE2EPagesLikeSmoke(t *testing.T) { - if os.Getenv("WASM_BROWSER_TEST") != "1" { - t.Skip("set WASM_BROWSER_TEST=1 to run browser E2E tests") - } - if _, err := os.Stat(filepath.Join("example", "main.wasm")); err != nil { - t.Skip("example/main.wasm is missing; run make build-example") - } - - server, url, err := serveBrowserTestDirWithHeaders("example", false) - if err != nil { - t.Fatalf("start pages-like server: %v", err) - } - defer server.Shutdown(context.Background()) - - allocCtx, cancel := newBrowserAllocator() - defer cancel() - - ctx, cancel := chromedp.NewContext(allocCtx) - defer cancel() - ctx, cancel = context.WithTimeout(ctx, 90*time.Second) - defer cancel() - - var consoleLines []string - chromedp.ListenTarget(ctx, func(event interface{}) { - if ev, ok := event.(*cdpruntime.EventConsoleAPICalled); ok { - var parts []string - for _, arg := range ev.Args { - if arg.Value != nil { - parts = append(parts, string(arg.Value)) - } - } - if len(parts) > 0 { - consoleLines = append(consoleLines, strings.Join(parts, " ")) - } - } - }) - - var ready bool - var isolated bool - var lastErr error - for attempt := 0; attempt < 5; attempt++ { - ready = false - isolated = false - lastErr = chromedp.Run(ctx, - chromedp.Navigate(url), - chromedp.WaitReady("body"), - chromedp.Poll( - `window.crossOriginIsolated === true && typeof window.runDemo === "function"`, - &ready, - chromedp.WithPollingInterval(250*time.Millisecond), - chromedp.WithPollingTimeout(30*time.Second), - ), - chromedp.Evaluate(`window.crossOriginIsolated === true`, &isolated), - ) - if lastErr == nil && ready && isolated { - break - } - if attempt < 4 { - time.Sleep(500 * time.Millisecond) - } - } - if lastErr != nil { - t.Fatalf("pages-like app did not initialize: %v\nconsole:\n%s", lastErr, strings.Join(consoleLines, "\n")) - } - if !ready { - t.Fatalf("pages-like app did not expose runDemo") - } - if !isolated { - t.Fatalf("pages-like app is not cross-origin isolated\nconsole:\n%s", strings.Join(consoleLines, "\n")) - } -} - func TestBrowserE2EMultiContextOPFS(t *testing.T) { if os.Getenv("WASM_BROWSER_TEST") != "1" { t.Skip("set WASM_BROWSER_TEST=1 to run browser E2E tests") diff --git a/example/enable-threads.js b/example/enable-threads.js deleted file mode 100644 index 69ecdca..0000000 --- a/example/enable-threads.js +++ /dev/null @@ -1,65 +0,0 @@ -// This script enables SharedArrayBuffer via a service worker -if(typeof window === 'undefined') { - self.addEventListener("install", () => self.skipWaiting()); - self.addEventListener("activate", e => e.waitUntil(self.clients.claim())); - - async function handleFetch(request) { - if(request.cache === "only-if-cached" && request.mode !== "same-origin") { - return; - } - - if(request.mode === "no-cors") { - request = new Request(request.url, { - cache: request.cache, - credentials: "omit", - headers: request.headers, - integrity: request.integrity, - destination: request.destination, - keepalive: request.keepalive, - method: request.method, - mode: request.mode, - redirect: request.redirect, - referrer: request.referrer, - referrerPolicy: request.referrerPolicy, - signal: request.signal, - }); - } - - let r = await fetch(request).catch(e => console.error(e)); - - if(r.status === 0) { - return r; - } - - const headers = new Headers(r.headers); - headers.set("Cross-Origin-Embedder-Policy", "credentialless"); - headers.set("Cross-Origin-Opener-Policy", "same-origin"); - - return new Response(r.body, { status: r.status, statusText: r.statusText, headers }); - } - - self.addEventListener("fetch", function(e) { - e.respondWith(handleFetch(e.request)); - }); - -} else { - (async function() { - if(window.crossOriginIsolated !== false) return; - - let registration = await navigator.serviceWorker.register(window.document.currentScript.src).catch(e => console.error("COOP/COEP Service Worker failed to register:", e)); - if(registration) { - console.log("COOP/COEP Service Worker registered", registration.scope); - - registration.addEventListener("updatefound", () => { - console.log("Reloading page to use updated COOP/COEP Service Worker."); - window.location.reload(); - }); - - // If the registration is active, but it's not controlling the page - if(registration.active && !navigator.serviceWorker.controller) { - console.log("Reloading page to use COOP/COEP Service Worker."); - window.location.reload(); - } - } - })(); -} \ No newline at end of file diff --git a/example/index.html b/example/index.html index d83eb7b..9797de2 100644 --- a/example/index.html +++ b/example/index.html @@ -4,8 +4,6 @@ wasmsqlite Demo - -