diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4019ada..6abca16 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -84,3 +84,22 @@ jobs: - name: Build static docs run: bun run build --filter=@webviewjs/docs + + macos-native: + name: macOS native Node and Bun regressions + runs-on: macos-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.4.2 + - uses: actions/setup-node@v4 + with: + node-version: 24 + - uses: dtolnay/rust-toolchain@stable + - run: bun install --frozen-lockfile + - name: Build the local addon and public TypeScript API + run: bun --filter @webviewjs/webview build + - name: Run real AppKit regressions in isolated processes + run: bun --filter @webviewjs/webview test:native:macos diff --git a/packages/webview/Cargo.lock b/packages/webview/Cargo.lock index a1c0231..1ed9a90 100644 --- a/packages/webview/Cargo.lock +++ b/packages/webview/Cargo.lock @@ -3332,7 +3332,7 @@ dependencies = [ [[package]] name = "tao" version = "0.37.2" -source = "git+https://github.com/webviewjs/tao?rev=9bb2bdc097e430f924a69add056ae55335492ab7#9bb2bdc097e430f924a69add056ae55335492ab7" +source = "git+https://github.com/webviewjs/tao?rev=73ab3e94986f045ad379faee9b2560bffd84012c#73ab3e94986f045ad379faee9b2560bffd84012c" dependencies = [ "bitflags 2.13.2", "block2", @@ -3359,7 +3359,7 @@ dependencies = [ "parking_lot", "percent-encoding", "raw-window-handle", - "tao-macros 0.1.4 (git+https://github.com/webviewjs/tao?rev=9bb2bdc097e430f924a69add056ae55335492ab7)", + "tao-macros 0.1.4 (git+https://github.com/webviewjs/tao?rev=73ab3e94986f045ad379faee9b2560bffd84012c)", "unicode-segmentation", "url", "windows 0.62.2", @@ -3382,7 +3382,7 @@ dependencies = [ [[package]] name = "tao-macros" version = "0.1.4" -source = "git+https://github.com/webviewjs/tao?rev=9bb2bdc097e430f924a69add056ae55335492ab7#9bb2bdc097e430f924a69add056ae55335492ab7" +source = "git+https://github.com/webviewjs/tao?rev=73ab3e94986f045ad379faee9b2560bffd84012c#73ab3e94986f045ad379faee9b2560bffd84012c" dependencies = [ "proc-macro2", "quote", diff --git a/packages/webview/Cargo.toml b/packages/webview/Cargo.toml index 2e7a861..25bfc7f 100644 --- a/packages/webview/Cargo.toml +++ b/packages/webview/Cargo.toml @@ -45,7 +45,7 @@ objc2-app-kit = { version = "0.3.2", default-features = false, features = ["NSAp objc2-foundation = { version = "0.3.2", default-features = false, features = ["NSData"] } [patch.crates-io] -tao = { git = "https://github.com/webviewjs/tao", rev = "9bb2bdc097e430f924a69add056ae55335492ab7" } +tao = { git = "https://github.com/webviewjs/tao", rev = "73ab3e94986f045ad379faee9b2560bffd84012c" } [build-dependencies] napi-build = "2" diff --git a/packages/webview/__test__/integration/README.md b/packages/webview/__test__/integration/README.md new file mode 100644 index 0000000..39d2169 --- /dev/null +++ b/packages/webview/__test__/integration/README.md @@ -0,0 +1,42 @@ +# macOS native regressions + +Build the local addon and TypeScript API, then opt into real GUI tests: + +```sh +bun --filter @webviewjs/webview build +bun --filter @webviewjs/webview test:native:macos +``` + +Requires a logged-in macOS desktop session, Node.js 24+ and Bun on PATH. Run +without interacting with the windows. These tests use the compiled public API +and real N-API addon, never the fake binding preload used by `runtime/` tests. +They skip unless on macOS with `WEBVIEW_NATIVE_TESTS=1`. + +The parent Bun test process serves HTTP while a fresh main-thread Node or Bun +child owns AppKit. A 25-second watchdog kills a blocked child; every child is +reaped and the server is closed, including on assertion failures. Native +resources and the application pump are explicitly disposed on normal exit. + +- [Copilot CLI #5398](https://github.com/github/copilot-cli/issues/5398): adapted + from the issue's reproduction to load `dist/index.js` locally. Uses + `whenReady({ interval: 50, ref: false })`, localhost, inline HTML and `data:` + navigation, page timers, HTTP fetches, IPC, JS reads and DOM mutation. Each + page must load before another window is created or focus is requested. After + seven seconds without input, also exercises repeated manual pumps, multiple + windows, resize, focus and cleanup. Serving HTTP in the parent isolates server + availability from native pump blocking in the child. +- [WebviewJS #91](https://github.com/webviewjs/webview/issues/91): checks all 16 + combinations of decorations/resizable/minimizable/shadow after webview + creation, style mutations, explicit shadow disabling and runtime changes. + This asserts AppKit `hasShadow` state; visual compositor appearance requires + human inspection. + +Passing on one macOS version does not establish that the macOS 26 loading stall +is resolved. Retest on the affected OS before claiming that result. These tests +do not validate Windows or Linux runtime behavior. + +Known Wry 0.55.1 limitation: `data:` pages load and execute JavaScript, but their +IPC messages are discarded in Wry's macOS delegate because `http::Uri` cannot +represent opaque data URLs. The tests assert data-page timers through JavaScript +evaluation and require IPC from HTTP and inline HTML. This is separate from Tao +pump scheduling and remains unfixed by this dependency update. diff --git a/packages/webview/__test__/integration/fixtures/macos.mjs b/packages/webview/__test__/integration/fixtures/macos.mjs new file mode 100644 index 0000000..946bba6 --- /dev/null +++ b/packages/webview/__test__/integration/fixtures/macos.mjs @@ -0,0 +1,145 @@ +// Real addon only: this child must run on the AppKit main thread, outside bun:test. +import { createRequire } from 'node:module'; +import { setTimeout as delay } from 'node:timers/promises'; + +const require = createRequire(import.meta.url); +const { Application } = require('../../../dist/index.js'); +const app = new Application(); +const windows = []; +const views = []; + +function check(value, message) { + if (!value) throw new Error(message); +} + +async function until(predicate, message) { + const deadline = Date.now() + 10000; + while (!predicate()) { + check(Date.now() < deadline, message); + await delay(50); + } +} + +try { + // Match CanvasWindowManager, including the unreferenced 50ms pump. + const keepAlive = setInterval(() => {}, 1000); + try { + await app.whenReady({ interval: 50, ref: false }); + if (process.argv[2] === 'shadows') { + let combinations = 0; + for (const decorations of [false, true]) { + for (const resizable of [false, true]) { + for (const minimizable of [false, true]) { + for (const shadow of [false, true]) { + const win = app.createBrowserWindow({ decorations, resizable, minimizable, macosHasShadow: shadow }); + windows.push(win); + const view = win.createWebview({ html: '

Shadow regression

' }); + views.push(view); + check( + win.hasShadow() === shadow, + `initial shadow: ${JSON.stringify({ decorations, resizable, minimizable, shadow })}`, + ); + for (const enabled of [true, false]) { + win.setDecorations(enabled); + win.setResizable(enabled); + win.setMinimizable(enabled); + check(win.hasShadow() === shadow, 'style mutation changed shadow'); + } + for (const enabled of [!shadow, shadow]) { + win.setHasShadow(enabled); + check(win.hasShadow() === enabled, 'runtime shadow mutation'); + } + view.dispose(); + win.dispose(); + combinations++; + } + } + } + } + console.log(JSON.stringify({ combinations })); + } else { + const url = process.argv[3]; + const html = `

hello

`; + let ipc = 0; + const messages = []; + for (const options of [{ url }, { html }, { url: `data:text/html,${encodeURIComponent(html)}` }]) { + const win = app.createBrowserWindow({ + title: 'WKWebView pump regression', + width: 400, + height: 250, + logical: true, + }); + windows.push(win); + const view = win.createWebview(options); + views.push(view); + const received = { count: 0 }; + messages.push(received); + view.onIpcMessage(() => { + ipc++; + received.count++; + }); + // Verify each page before creating another window or requesting focus. + let result; + await until(() => { + if (result === undefined) + view.evaluateScriptWithCallback("document.querySelector('h1')?.textContent", (error, value) => { + if (error) throw error; + result = value; + }); + if (result && !result.includes('hello')) result = undefined; + return result?.includes('hello'); + }, 'page never loaded without interaction'); + view.evaluateScript("document.querySelector('h1').textContent='updated';window.ipc.postMessage('evaluated')"); + } + // Wry 0.55.1 drops data: IPC because http::Uri rejects opaque data URLs. + // Check data-page JS timers directly; require IPC from HTTP and inline HTML. + await until( + () => messages.slice(0, 2).every((message) => message.count >= 3), + 'IPC and page timers did not progress', + ); + // Match the issue's observation period, with no focus or input intervention. + await delay(7000); + const dataTicks = await new Promise((resolve, reject) => + views[2].evaluateScriptWithCallback('window.ticks', (error, value) => (error ? reject(error) : resolve(value))), + ); + check(Number(dataTicks) >= 2, 'data page timer did not progress'); + app.stop(); + for (let i = 0; i < 20; i++) { + check(app.pumpEvents(), 'repeated external pump stopped early'); + await delay(50); + } + app.run({ interval: 50, ref: false }); + // Only manipulate native windows after unaided navigation has passed. + for (const win of windows) { + win.setSize(460, 300, true); + win.focus(); + await delay(100); + check(win.isFocused(), 'window did not receive focus'); + check(win.getInnerSize(true).width === 460, 'resize failed'); + } + for (const view of views) { + const value = await new Promise((resolve) => + view.evaluateScriptWithCallback("document.querySelector('h1').textContent", (error, value) => { + if (error) throw error; + resolve(value); + }), + ); + check(value.includes('updated'), 'JavaScript DOM mutation failed'); + } + console.log(JSON.stringify({ pages: views.length, ipc, dataTicks: Number(dataTicks) })); + } + } finally { + clearInterval(keepAlive); + } +} finally { + for (const view of views) if (!view.isDisposed()) view.dispose(); + for (const win of windows) { + if (!win.isDisposed()) win.dispose(); + check(win.isDisposed(), 'window cleanup failed'); + } + app.exit(); + app.stop(); + for (let i = 0; i < 3; i++) app.pumpEvents(); +} +// Keep the embedding host alive after shutdown to expose stale native observers. +await delay(200); diff --git a/packages/webview/__test__/integration/macos.test.ts b/packages/webview/__test__/integration/macos.test.ts new file mode 100644 index 0000000..fd6092d --- /dev/null +++ b/packages/webview/__test__/integration/macos.test.ts @@ -0,0 +1,71 @@ +import { expect, test } from 'bun:test'; +import { spawn } from 'node:child_process'; +import { createServer } from 'node:http'; +import { fileURLToPath } from 'node:url'; + +// Opt in: these tests open real AppKit windows and must never use the fake preload. +const nativeTest = process.platform === 'darwin' && process.env.WEBVIEW_NATIVE_TESTS === '1' ? test : test.skip; +const fixture = fileURLToPath(new URL('./fixtures/macos.mjs', import.meta.url)); + +for (const runtime of ['node', 'bun']) { + for (const scenario of ['loading', 'shadows']) { + nativeTest( + `${runtime}: real macOS ${scenario}`, + async () => { + let roots = 0; + let ticks = 0; + const server = createServer((req, res) => { + if (req.url === '/tick') { + ticks++; + res.writeHead(204).end(); + return; + } + roots++; + res.writeHead(200, { 'content-type': 'text/html' }); + res.end( + `

hello

`, + ); + }); + await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); + const address = server.address(); + if (!address || typeof address === 'string') throw new Error('Missing HTTP address'); + // The HTTP server stays responsive even if a native pump blocks its child. + const child = spawn(runtime, [fixture, scenario, `http://127.0.0.1:${address.port}/`], { + stdio: ['ignore', 'pipe', 'pipe'], + }); + let output = ''; + let errors = ''; + child.stdout.on('data', (chunk) => { + output += chunk; + }); + child.stderr.on('data', (chunk) => { + errors += chunk; + }); + const watchdog = setTimeout(() => child.kill('SIGKILL'), 25000); + const completion = new Promise((resolve, reject) => { + child.once('error', reject); + child.once('close', resolve); + }); + try { + expect(await completion, errors).toBe(0); + const result = JSON.parse(output.trim()); + console.info(runtime, scenario, { ...result, roots, ticks }); + if (scenario === 'loading') { + expect(result.pages).toBe(3); + expect(result.ipc).toBeGreaterThanOrEqual(9); + expect(roots).toBeGreaterThanOrEqual(1); + expect(ticks).toBeGreaterThanOrEqual(2); + } else { + expect(result.combinations).toBe(16); + } + } finally { + clearTimeout(watchdog); + if (child.exitCode === null && child.signalCode === null) child.kill('SIGKILL'); + await completion.catch(() => {}); + await new Promise((resolve) => server.close(() => resolve())); + } + }, + 30000, + ); + } +} diff --git a/packages/webview/__test__/manual-verification.md b/packages/webview/__test__/manual-verification.md index 483a03e..cfbffba 100644 --- a/packages/webview/__test__/manual-verification.md +++ b/packages/webview/__test__/manual-verification.md @@ -3,6 +3,11 @@ Run `bun run build` once before these checks. Launch examples from the repository root with `bun run apps/examples/.ts`. +For opt-in macOS tests through the real Node/Bun addon, see +[integration/README.md](integration/README.md). These cover unaided WKWebView +loading, external event pumping and shadow state; visual shadows still need +human inspection. + ## Desktop checks - **Drag regions:** Run `drag-region.ts`. Drag the titlebar background and a diff --git a/packages/webview/package.json b/packages/webview/package.json index a5f49eb..b989f4a 100644 --- a/packages/webview/package.json +++ b/packages/webview/package.json @@ -76,7 +76,8 @@ "clippy": "cargo clippy -- -D warnings", "docs": "cargo doc --no-deps --open", "update": "bun update", - "setup": "bash ./scripts/install-linux-deps.sh" + "setup": "bash ./scripts/install-linux-deps.sh", + "test:native:macos": "WEBVIEW_NATIVE_TESTS=1 bun test __test__/integration" }, "devDependencies": { "@napi-rs/cli": "^3.7.4",