Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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/`
Expand Down Expand Up @@ -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`
Expand All @@ -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

Expand All @@ -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

Expand Down
72 changes: 0 additions & 72 deletions browser_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
65 changes: 0 additions & 65 deletions example/enable-threads.js

This file was deleted.

2 changes: 0 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wasmsqlite Demo</title>
<!-- Enable SharedArrayBuffer via Service Worker -->
<script src="enable-threads.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
Expand Down
Loading