From 8b073654facf2359206b21de9fb32281b7447c42 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 2 Dec 2026 23:37:21 +0100 Subject: [PATCH 1/2] [DO NOT MERGE] Debug restricted session failures on Windows CI Fail the connection when browser.getUserContexts fails with an unexpected error, instead of treating the session as not restricted. Enable debug logs on the Windows CI jobs. --- .github/workflows/ci.yml | 1 + src/firefox/bidi.ts | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdb163fe..6f6b6166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,7 @@ jobs: run: npm run test:coverage env: FIREFOX_PATH: ${{ steps.setup-firefox.outputs.firefox-path }} + DEBUG: ${{ matrix.os == 'windows-latest' && 'firefox-mcp' || '' }} - name: Upload coverage reports to Codecov if: >- diff --git a/src/firefox/bidi.ts b/src/firefox/bidi.ts index 051d0fef..2c338c35 100644 --- a/src/firefox/bidi.ts +++ b/src/firefox/bidi.ts @@ -143,11 +143,10 @@ export class BiDiFacade extends EventEmitter { try { await this.sendCommand('browser.getUserContexts', {}); } catch (error) { - if (error instanceof RestrictedSessionError) { - this.userContext = userContext; - } else { - logDebug('Unable to check if the session is restricted', error); + if (!(error instanceof RestrictedSessionError)) { + throw error; } + this.userContext = userContext; } } From a3ca65d597aebb90e6c7b78aa8732c32460697bc Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 2 Dec 2026 23:48:31 +0100 Subject: [PATCH 2/2] [DO NOT MERGE] Log BiDi connection timings and repeat restricted session tests Log how long getBidi, the WebSocket opening and browser.getUserContexts take. Show the stderr of the MCP server in tests when DEBUG is set. Run the MCP restricted session tests 20 times on the Windows CI jobs. --- .github/workflows/ci.yml | 16 ++++++++++++++++ src/firefox/bidi.ts | 12 ++++++++++++ tests/helpers/mcp.ts | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f6b6166..68be872c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,22 @@ jobs: FIREFOX_PATH: ${{ steps.setup-firefox.outputs.firefox-path }} DEBUG: ${{ matrix.os == 'windows-latest' && 'firefox-mcp' || '' }} + - name: Repeat restricted session tests + if: ${{ always() && matrix.os == 'windows-latest' }} + shell: bash + env: + FIREFOX_PATH: ${{ steps.setup-firefox.outputs.firefox-path }} + DEBUG: firefox-mcp + run: | + failures=0 + for i in $(seq 1 20); do + echo "::group::Iteration $i" + npx vitest run tests/integration/mcp/restricted-session.test.ts tests/integration/mcp/restricted-session-restart.test.ts || { failures=$((failures + 1)); echo "::warning::Iteration $i failed"; } + echo "::endgroup::" + done + echo "Failed iterations: $failures / 20" + [ "$failures" -eq 0 ] + - name: Upload coverage reports to Codecov if: >- github.event_name != 'pull_request' && matrix.os == 'ubuntu-latest' && diff --git a/src/firefox/bidi.ts b/src/firefox/bidi.ts index 2c338c35..c1c679a2 100644 --- a/src/firefox/bidi.ts +++ b/src/firefox/bidi.ts @@ -140,9 +140,12 @@ export class BiDiFacade extends EventEmitter { * depends on a Firefox pref. A restricted session rejects browser.getUserContexts. */ async detectRestrictedUserContext(userContext: string): Promise { + const start = Date.now(); try { await this.sendCommand('browser.getUserContexts', {}); + logDebug(`browser.getUserContexts succeeded after ${Date.now() - start}ms`); } catch (error) { + logDebug(`browser.getUserContexts failed after ${Date.now() - start}ms`, error); if (!(error instanceof RestrictedSessionError)) { throw error; } @@ -182,12 +185,21 @@ export class BiDiFacade extends EventEmitter { params: FirefoxCommands[T]['params'] = {}, { timeout = 10000 }: { timeout?: number } = {} ): Promise { + const start = Date.now(); const bidi = await this.driver.getBidi(); // bidi.socket is a Node.js `ws` WebSocket (EventEmitter-style), but typed as browser WebSocket const ws = bidi.socket as any; + if (ws.readyState !== 1) { + logDebug( + `${method}: getBidi took ${Date.now() - start}ms, WebSocket readyState ${ws.readyState}` + ); + } // Wait for WebSocket to be ready before sending await this.waitForWebSocketOpen(ws); + if (Date.now() - start > 500) { + logDebug(`${method}: WebSocket ready after ${Date.now() - start}ms`); + } const id = this.nextCommandId++; diff --git a/tests/helpers/mcp.ts b/tests/helpers/mcp.ts index c228d0ba..1adcb5ba 100644 --- a/tests/helpers/mcp.ts +++ b/tests/helpers/mcp.ts @@ -70,7 +70,7 @@ export async function startMcpServer(serverArgs: string[] = []): Promise