Skip to content

Commit fd536c8

Browse files
committed
feat: enhance devcontainer with Playwright MCP integration and browser dependencies
1 parent 6f81e32 commit fd536c8

3 files changed

Lines changed: 153 additions & 2 deletions

File tree

.devcontainer/.claude.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
{
2-
"bypassPermissionsModeAccepted": true
2+
"bypassPermissionsModeAccepted": true,
3+
"mcpServers": {
4+
"playwright": {
5+
"command": "npx",
6+
"args": [
7+
"-y",
8+
"@playwright/mcp@latest",
9+
"--browser",
10+
"chromium"
11+
]
12+
}
13+
}
314
}

.devcontainer/Dockerfile

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,53 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2727
vim \
2828
&& apt-get clean && rm -rf /var/lib/apt/lists/*
2929

30+
# Install Chromium for Playwright (consistent across all architectures)
31+
RUN apt-get update && apt-get install -y --no-install-recommends \
32+
chromium \
33+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
34+
35+
# Install Playwright browser dependencies for Chromium
36+
# These are required for @playwright/mcp to run browsers
37+
RUN apt-get update && apt-get install -y --no-install-recommends \
38+
libnspr4 \
39+
libnss3 \
40+
libdbus-1-3 \
41+
libatk1.0-0 \
42+
libatk-bridge2.0-0 \
43+
libcups2 \
44+
libxkbcommon0 \
45+
libatspi2.0-0 \
46+
libxcomposite1 \
47+
libxdamage1 \
48+
libxfixes3 \
49+
libxrandr2 \
50+
libgbm1 \
51+
libasound2 \
52+
libxshmfence1 \
53+
libdrm2 \
54+
libx11-6 \
55+
libx11-xcb1 \
56+
libxcb1 \
57+
libxext6 \
58+
libcairo2 \
59+
libpango-1.0-0 \
60+
libpangocairo-1.0-0 \
61+
libgdk-pixbuf2.0-0 \
62+
libgtk-3-0 \
63+
libglib2.0-0 \
64+
xvfb \
65+
libfontconfig1 \
66+
libfreetype6 \
67+
xfonts-scalable \
68+
fonts-liberation \
69+
fonts-noto-color-emoji \
70+
fonts-unifont \
71+
fonts-ipafont-gothic \
72+
fonts-wqy-zenhei \
73+
fonts-tlwg-loma-otf \
74+
fonts-freefont-ttf \
75+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
76+
3077
# Ensure default node user has access to /usr/local/share
3178
RUN mkdir -p /usr/local/share/npm-global && \
3279
chown -R node:node /usr/local/share
@@ -54,6 +101,13 @@ RUN ARCH=$(dpkg --print-architecture) && \
54101
sudo dpkg -i "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
55102
rm "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb"
56103

104+
# Install Playwright and Chromium browser (consistent across all architectures)
105+
RUN npm install -g @playwright/test && \
106+
npx playwright install chromium && \
107+
# Ensure node user has access to Playwright cache
108+
mkdir -p /home/node/.cache && \
109+
chown -R node:node /home/node/.cache
110+
57111
# Set up non-root user
58112
USER node
59113

@@ -85,7 +139,6 @@ RUN echo "source /home/node/.zshrc.devcontainer" >> /home/node/.zshrc
85139
# Install Claude
86140
RUN npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}
87141

88-
89142
# Copy and set up firewall script
90143
COPY init-firewall.sh /usr/local/bin/
91144
USER root

.devcontainer/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# DevContainer with Playwright MCP Integration
2+
3+
This devcontainer is configured to work with Claude Code and includes the Playwright MCP server for browser automation capabilities.
4+
5+
## Features
6+
7+
- **Claude Code CLI**: Pre-installed and configured
8+
- **Playwright MCP Server**: Integrated for browser automation and screenshot capabilities
9+
- **Browser Dependencies**: All required system libraries for running Chromium headless
10+
- **Network Security**: Firewall configuration for controlled network access
11+
12+
## Playwright MCP Server
13+
14+
The Playwright MCP server is configured in `.claude.json` and provides browser automation tools to Claude Code, including:
15+
16+
- Navigate to URLs
17+
- Click elements
18+
- Fill forms
19+
- Take screenshots
20+
- Execute JavaScript
21+
- Interact with page elements
22+
23+
### Usage
24+
25+
Once the devcontainer is rebuilt, Claude Code will automatically have access to Playwright MCP tools. You can use these tools through natural language requests like:
26+
27+
- "Take a screenshot of http://localhost:5173"
28+
- "Navigate to my site and click the contact button"
29+
- "Fill out the form with test data"
30+
31+
### Configuration
32+
33+
The MCP server configuration is in `.devcontainer/.claude.json`:
34+
35+
```json
36+
{
37+
"mcpServers": {
38+
"playwright": {
39+
"command": "npx",
40+
"args": ["-y", "@playwright/mcp@latest"]
41+
}
42+
}
43+
}
44+
```
45+
46+
## Rebuilding the Container
47+
48+
After making changes to the Dockerfile or devcontainer configuration:
49+
50+
1. In VS Code: Command Palette → "Dev Containers: Rebuild Container"
51+
2. Or use the rebuild button in the bottom-left corner
52+
53+
## System Dependencies
54+
55+
The container includes these Playwright browser dependencies:
56+
- libnspr4, libnss3, libdbus-1-3
57+
- libatk1.0-0, libatk-bridge2.0-0
58+
- libcups2, libxkbcommon0, libatspi2.0-0
59+
- libxcomposite1, libxdamage1, libxfixes3
60+
- libxrandr2, libgbm1, libasound2
61+
- fonts-liberation, fonts-noto-color-emoji
62+
- And other required X11 and graphics libraries
63+
64+
## Testing the Integration
65+
66+
To verify Playwright MCP is working:
67+
68+
```bash
69+
# Check if Playwright MCP can be run
70+
npx -y @playwright/mcp@latest --version
71+
72+
# The MCP tools will be automatically available in Claude Code sessions
73+
```
74+
75+
## Troubleshooting
76+
77+
If browser automation isn't working:
78+
79+
1. Ensure the container has been rebuilt after adding the Dockerfile changes
80+
2. Check that `.claude.json` is correctly copied to `/home/node/.claude/.claude.json`
81+
3. Verify browser dependencies are installed: `dpkg -l | grep libnspr4`
82+
4. Check Claude Code can access the MCP server in the session
83+
84+
## Additional Resources
85+
86+
- [Playwright MCP Documentation](https://github.com/microsoft/playwright-mcp)
87+
- [Claude Code MCP Integration](https://docs.claude.com/en/docs/claude-code)

0 commit comments

Comments
 (0)