Skip to content

feat(mcp): add network offline state tools#39459

Open
MatSFT wants to merge 6 commits intomicrosoft:mainfrom
MatSFT:feat/mcp-network-offline-tools
Open

feat(mcp): add network offline state tools#39459
MatSFT wants to merge 6 commits intomicrosoft:mainfrom
MatSFT:feat/mcp-network-offline-tools

Conversation

@MatSFT
Copy link

@MatSFT MatSFT commented Feb 27, 2026

Summary

  • Add two new CLI & MCP tools to manage browser network state:
    • network_state: Get current network state (online/offline)
    • set_network_state: Set network state to online or offline
  • Add isOffline() method to BrowserContext API to query the current offline state

Test plan

  • Run MCP tests: npx playwright test --config=tests/mcp/playwright.config.ts --grep network
  • Manual testing CLI:
    1. Start Playwright cli
    2. Call set_network_state offline
    3. Navigate to a page - should fail with network error
    4. Call `set_network_state online``
    5. Navigate to a page - should succeed
  • Manual testing MCP:
    1. Start Playwright MCP
    2. Launch copilot and setup mcp
    3. Ask copilot to launch any website, change the network to offline, reload, verify offline, change to online, reload, verify online

🤖 Generated with Claude Code

Add two new MCP tools to manage browser network offline state:
- browser_network_status: Get current network state (online/offline)
- browser_network_set_offline: Set network state to online or offline

Also adds isOffline() method to BrowserContext API to query the
current offline state from the server.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MatSFT
Copy link
Author

MatSFT commented Feb 27, 2026

@microsoft-github-policy-service agree company="Microsoft"

@MatSFT MatSFT marked this pull request as draft February 27, 2026 17:10
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Add tests for browser_network_status and browser_network_set_offline
MCP tools that were implemented in the previous commit. Also adds CLI
commands (network-status, network-set-offline) to expose these tools
via the CLI interface.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Update the network offline test to match error messages from all
browsers:
- Chrome: net::ERR_INTERNET_DISCONNECTED
- Firefox: NS_ERROR_OFFLINE
- WebKit: WebKit encountered an internal error

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

- Rename browser_network_status to browser_network_state
- Rename browser_network_set_offline to browser_set_network_state
- Change input from { offline: boolean } to { state: "online" | "offline" }
- Update CLI commands: network-status → network-state, network-set-offline → set-network-state
- Update CLI option from --offline to --state

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MatSFT MatSFT force-pushed the feat/mcp-network-offline-tools branch from 7f318da to f8b2e66 Compare February 27, 2026 20:07
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@MatSFT
Copy link
Author

MatSFT commented Feb 27, 2026

The test failures do not seem relevant to the code changes

Copy link
Member

@yury-s yury-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you start with filing an issue that describes the use case?

@MatSFT
Copy link
Author

MatSFT commented Feb 27, 2026

@yury-s

Can you start with filing an issue that describes the use case?
How do I link this issue to my PR?
microsoft/playwright-mcp#696

mastank and others added 2 commits February 27, 2026 17:11
- Remove browser_network_state read-only tool and network-state CLI command
- Rename browser_set_network_state to browser_network_state_set
- Rename CLI command set-network-state to network-state-set

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove the isOffline() method that was added as part of the network
offline tools feature. The MCP implementation doesn't need this
public API method.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

Test results for "MCP"

5 failed
❌ [chromium] › mcp/roots.spec.ts:47 › check that trace is saved in workspace @mcp-windows-latest
❌ [chromium] › mcp/tracing.spec.ts:21 › check that trace is saved with --save-trace @mcp-windows-latest
❌ [msedge] › mcp/roots.spec.ts:47 › check that trace is saved in workspace @mcp-windows-latest
❌ [firefox] › mcp/sse.spec.ts:171 › sse transport browser lifecycle (persistent) @mcp-macos-15
❌ [webkit] › mcp/sse.spec.ts:171 › sse transport browser lifecycle (persistent) @mcp-macos-15

5193 passed, 171 skipped


Merge workflow run.

@github-actions
Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [webkit-library] › library/download.spec.ts:399 › download event › should save downloads to artifactsDir @webkit-ubuntu-22.04-node20

8 flaky ⚠️ [chromium-library] › library/trace-viewer.spec.ts:1216 › should display language-specific locators `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:356 › screencast › should capture navigation `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:735 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-page] › page/page-request-continue.spec.ts:754 › propagate headers cross origin redirect after interception `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-page] › page/page-request-continue.spec.ts:754 › propagate headers cross origin redirect after interception `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/beforeunload.spec.ts:188 › does not get stalled by beforeUnload `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/trace-viewer.spec.ts:1216 › should display language-specific locators `@firefox-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:433 › should work behind reverse proxy `@macos-latest-node20`

38654 passed, 841 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants