Skip to content
Closed
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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ jobs:
run: npm run test:coverage
env:
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: >-
Expand Down
19 changes: 15 additions & 4 deletions src/firefox/bidi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ export class BiDiFacade extends EventEmitter<FirefoxEventMap> {
* depends on a Firefox pref. A restricted session rejects browser.getUserContexts.
*/
async detectRestrictedUserContext(userContext: string): Promise<void> {
const start = Date.now();
try {
await this.sendCommand('browser.getUserContexts', {});
logDebug(`browser.getUserContexts succeeded after ${Date.now() - start}ms`);
} catch (error) {
if (error instanceof RestrictedSessionError) {
this.userContext = userContext;
} else {
logDebug('Unable to check if the session is restricted', error);
logDebug(`browser.getUserContexts failed after ${Date.now() - start}ms`, error);
if (!(error instanceof RestrictedSessionError)) {
throw error;
}
this.userContext = userContext;
}
}

Expand Down Expand Up @@ -183,12 +185,21 @@ export class BiDiFacade extends EventEmitter<FirefoxEventMap> {
params: FirefoxCommands[T]['params'] = {},
{ timeout = 10000 }: { timeout?: number } = {}
): Promise<FirefoxCommands[T]['returnType']> {
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++;

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function startMcpServer(serverArgs: string[] = []): Promise<McpTest
USERPROFILE: home,
NODE_ENV: 'production',
},
stderr: 'ignore',
stderr: process.env.DEBUG ? 'inherit' : 'ignore',
});
const client = new Client({ name: 'firefox-mcp-tests', version: '0.0.0' });
let toolListChanges = 0;
Expand Down
Loading