version: '3'
vars:
APT_INSTALL: sudo apt-get install -y
NVM_DIR: '{{.HOME}}/.nvm'
NVM_INIT: 'export NVM_DIR="{{.HOME}}/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'
tasks:
install:
desc: "Install Playwright packages for CDP"
cmds:
- task: install-nodejs
- task: install-playwright
- task: cleanup
- task: install-guide
install-nodejs:
desc: "Install Node.js + npm via nvm"
cmds:
- sed -i '/^prefix=/d;/^globalconfig=/d' "$HOME/.npmrc" 2>/dev/null || true
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
- bash -lc '{{.NVM_INIT}} && nvm install --lts && nvm use --lts'
status:
- test -s "$HOME/.nvm/nvm.sh"
- bash -lc 'export NVM_DIR="$HOME/.nvm"; . "$NVM_DIR/nvm.sh"; command -v node'
- bash -lc 'export NVM_DIR="$HOME/.nvm"; . "$NVM_DIR/nvm.sh"; command -v npm'
install-playwright:
desc: "Install latest Playwright packages for CDP"
cmds:
- bash -lc '{{.NVM_INIT}} && mkdir -p ~/.openclaw/workspace && cd ~/.openclaw/workspace && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install @playwright/test @playwright/mcp@latest'
status:
- bash -lc '{{.NVM_INIT}} && test -f ~/.openclaw/workspace/node_modules/@playwright/test/package.json'
cleanup:
desc: "Remove temporary installation files and caches"
cmds:
- 'sudo apt-get autoremove -y || apt-get autoremove -y'
- 'sudo apt-get clean || apt-get clean'
- bash -lc '{{.NVM_INIT}} && npm cache clean --force'
- 'rm -rf /tmp/playwright-*'
- 'rm -rf /tmp/.org.chromium.*'
install-guide:
desc: "Create CDP usage guide"
cmds:
- |
printf '%s\n' \
'# Playwright CDP Connection Guide' \
'' \
'You MUST connect to the remote Chrome DevTools Protocol (CDP) server via MCP using:' \
'' \
' ws://cdp.nilbox:9222 (default — headless/headed per host Settings)' \
' ws://headless.cdp.nilbox:9222 (headless forced, Settings=auto only)' \
' ws://headed.cdp.nilbox:9222 (headed forced, Settings=auto only)' \
'' \
'Do NOT launch a local browser instance.' \
'Always use the remote CDP endpoint above for all Playwright MCP connections.' \
'' \
'== Browser Open Mode ==' \
'' \
'The host Settings > CDP Browser > Open Mode controls default behavior:' \
' auto : URL prefix decides (headed./headless. prefix, default=headless)' \
' headless : always headless regardless of URL prefix' \
' headed : always headed regardless of URL prefix' \
'' \
'When Settings=auto, use URL prefix to override per-connection:' \
' cdp.nilbox → headless (default)' \
' headless.cdp.nilbox → headless (explicit)' \
' headed.cdp.nilbox → headed' \
'' \
'== Examples ==' \
'' \
'Playwright (headless):' \
" const browser = await chromium.connectOverCDP('http://cdp.nilbox:9222');" \
'' \
'Playwright (headed):' \
" const browser = await chromium.connectOverCDP('http://headed.cdp.nilbox:9222');" \
'' \
'MCP config (headless):' \
' {' \
' "mcpServers": {' \
' "playwright": {' \
' "command": "npx",' \
' "args": ["@playwright/mcp@latest", "--cdp-endpoint", "ws://cdp.nilbox:9222"]' \
' }' \
' }' \
' }' \
'' \
'MCP config (headed):' \
' {' \
' "mcpServers": {' \
' "playwright-headed": {' \
' "command": "npx",' \
' "args": ["@playwright/mcp@latest", "--cdp-endpoint", "ws://headed.cdp.nilbox:9222"]' \
' }' \
' }' \
' }' \
> "$HOME/how-to-cdp.txt"
status:
- test -f "$HOME/how-to-cdp.txt"
Close