Skip to content

Commit 5c8bb4f

Browse files
authored
Merge pull request #18 from cloudflare/merge-0.0.30
Merge upstream playwright-mcp 0.0.30
2 parents 65e09d9 + a59b283 commit 5c8bb4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4762
-1642
lines changed

.github/workflows/cf_publish_release_npm.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ jobs:
1515
node-version: "20.x"
1616
registry-url: "https://registry.npmjs.org"
1717

18-
- name: Run npm ci
19-
run: npm ci
20-
21-
- name: Run playwright-mcp-cloudflare build
22-
run: |
23-
cd cloudflare
24-
npm run build
25-
2618
- name: Determine version
2719
id: version
2820
run: |
@@ -35,12 +27,20 @@ jobs:
3527
fi
3628
# Set the output for later steps
3729
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
30+
31+
- name: Run npm ci
32+
run: npm ci
33+
34+
- name: Run playwright-mcp-cloudflare build
35+
run: |
36+
cd cloudflare
37+
npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version
38+
npm run build
3839
3940
- name: Publish to npm
4041
run: |
4142
cd cloudflare
4243
cp ../README.md .
43-
npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version
4444
npm publish
4545
env:
4646
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

.github/workflows/ci.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- run: npm run build
2222
- name: Run ESLint
2323
run: npm run lint
24-
- run: npm run update-readme
2524
- name: Ensure no changes
2625
run: git diff --exit-code
2726

@@ -31,31 +30,56 @@ jobs:
3130
matrix:
3231
os: [ubuntu-latest, macos-latest, windows-latest]
3332
runs-on: ${{ matrix.os }}
34-
3533
steps:
3634
- uses: actions/checkout@v4
37-
3835
- name: Use Node.js 18
3936
uses: actions/setup-node@v4
4037
with:
41-
node-version: '18'
38+
# https://github.com/microsoft/playwright-mcp/issues/344
39+
node-version: '18.19'
4240
cache: 'npm'
43-
4441
- name: Install dependencies
4542
run: npm ci
46-
4743
- name: Playwright install
4844
run: npx playwright install --with-deps
49-
5045
- name: Install MS Edge
51-
if: ${{ matrix.os == 'macos-latest' }} # MS Edge is not preinstalled on macOS runners.
46+
# MS Edge is not preinstalled on macOS runners.
47+
if: ${{ matrix.os == 'macos-latest' }}
5248
run: npx playwright install msedge
53-
5449
- name: Build
5550
run: npm run build
51+
- name: Run tests
52+
run: npm test
5653

57-
- name: Install Playwright browsers
58-
run: npx playwright install --with-deps
59-
54+
test_docker:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: Use Node.js 18
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: '18'
62+
cache: 'npm'
63+
- name: Install dependencies
64+
run: npm ci
65+
- name: Playwright install
66+
run: npx playwright install --with-deps chromium
67+
- name: Build
68+
run: npm run build
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
- name: Build and push
72+
uses: docker/build-push-action@v6
73+
with:
74+
tags: playwright-mcp-dev:latest
75+
cache-from: type=gha
76+
cache-to: type=gha,mode=max
77+
load: true
6078
- name: Run tests
61-
run: npm test -- --forbid-only
79+
shell: bash
80+
run: |
81+
# Used for the Docker tests to share the test-results folder with the container.
82+
umask 0000
83+
npm run test -- --project=chromium-docker
84+
env:
85+
MCP_IN_DOCKER: 1

.github/workflows/publish.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
permissions:
99
contents: read
10-
id-token: write
10+
id-token: write # Needed for npm provenance
1111
steps:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-node@v4
@@ -21,4 +21,50 @@ jobs:
2121
- run: npm run ctest
2222
- run: npm publish --provenance
2323
env:
24-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25+
26+
publish-docker:
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
30+
id-token: write # Needed for OIDC login to Azure
31+
environment: allow-publishing-docker-to-acr
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Set up QEMU # Needed for multi-platform builds (e.g., arm64 on amd64 runner)
35+
uses: docker/setup-qemu-action@v3
36+
- name: Set up Docker Buildx # Needed for multi-platform builds
37+
uses: docker/setup-buildx-action@v3
38+
- name: Azure Login via OIDC
39+
uses: azure/login@v2
40+
with:
41+
client-id: ${{ secrets.AZURE_DOCKER_CLIENT_ID }}
42+
tenant-id: ${{ secrets.AZURE_DOCKER_TENANT_ID }}
43+
subscription-id: ${{ secrets.AZURE_DOCKER_SUBSCRIPTION_ID }}
44+
- name: Login to ACR
45+
run: az acr login --name playwright
46+
- name: Build and push Docker image
47+
id: build-push
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
file: ./Dockerfile # Adjust path if your Dockerfile is elsewhere
52+
platforms: linux/amd64,linux/arm64
53+
push: true
54+
tags: |
55+
playwright.azurecr.io/public/playwright/mcp:${{ github.event.release.tag_name }}
56+
playwright.azurecr.io/public/playwright/mcp:latest
57+
- uses: oras-project/setup-oras@v1
58+
- name: Set oras tags
59+
run: |
60+
attach_eol_manifest() {
61+
local image="$1"
62+
local today=$(date -u +'%Y-%m-%d')
63+
# oras is re-using Docker credentials, so we don't need to login.
64+
# Following the advice in https://portal.microsofticm.com/imp/v3/incidents/incident/476783820/summary
65+
oras attach --artifact-type application/vnd.microsoft.artifact.lifecycle --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$today" $image
66+
}
67+
# for each tag, attach the eol manifest
68+
for tag in $(echo ${{ steps.build-push.outputs.metadata['image.name'] }} | tr ',' '\n'); do
69+
attach_eol_manifest $tag
70+
done

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
lib/
22
node_modules/
33
test-results/
4+
playwright-report/
45
.vscode/mcp.json
6+
7+
.idea
8+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ LICENSE
44
!lib/**/*.js
55
!cli.js
66
!index.*
7+
!config.d.ts

Dockerfile

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,69 @@
1-
FROM node:22-bookworm-slim
1+
ARG PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
2+
3+
# ------------------------------
4+
# Base
5+
# ------------------------------
6+
# Base stage: Contains only the minimal dependencies required for runtime
7+
# (node_modules and Playwright system dependencies)
8+
FROM node:22-bookworm-slim AS base
9+
10+
ARG PLAYWRIGHT_BROWSERS_PATH
11+
ENV PLAYWRIGHT_BROWSERS_PATH=${PLAYWRIGHT_BROWSERS_PATH}
212

313
# Set the working directory
414
WORKDIR /app
515

6-
# Copy package.json and package-lock.json at this stage to leverage the build cache
7-
COPY package*.json ./
16+
RUN --mount=type=cache,target=/root/.npm,sharing=locked,id=npm-cache \
17+
--mount=type=bind,source=package.json,target=package.json \
18+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
19+
npm ci --omit=dev && \
20+
# Install system dependencies for playwright
21+
npx -y playwright-core install-deps chromium
822

9-
# Install dependencies
10-
RUN npm ci
23+
# ------------------------------
24+
# Builder
25+
# ------------------------------
26+
FROM base AS builder
1127

12-
# Install chromium and its dependencies, but only for headless mode
13-
RUN npx -y playwright install --with-deps --only-shell chromium
28+
RUN --mount=type=cache,target=/root/.npm,sharing=locked,id=npm-cache \
29+
--mount=type=bind,source=package.json,target=package.json \
30+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
31+
npm ci
1432

1533
# Copy the rest of the app
16-
COPY . .
34+
COPY *.json *.js *.ts .
35+
COPY src src/
1736

1837
# Build the app
1938
RUN npm run build
2039

40+
# ------------------------------
41+
# Browser
42+
# ------------------------------
43+
# Cache optimization:
44+
# - Browser is downloaded only when node_modules or Playwright system dependencies change
45+
# - Cache is reused when only source code changes
46+
FROM base AS browser
47+
48+
RUN npx -y playwright-core install --no-shell chromium
49+
50+
# ------------------------------
51+
# Runtime
52+
# ------------------------------
53+
FROM base
54+
55+
ARG PLAYWRIGHT_BROWSERS_PATH
56+
ARG USERNAME=node
57+
ENV NODE_ENV=production
58+
59+
# Set the correct ownership for the runtime user on production `node_modules`
60+
RUN chown -R ${USERNAME}:${USERNAME} node_modules
61+
62+
USER ${USERNAME}
63+
64+
COPY --from=browser --chown=${USERNAME}:${USERNAME} ${PLAYWRIGHT_BROWSERS_PATH} ${PLAYWRIGHT_BROWSERS_PATH}
65+
COPY --chown=${USERNAME}:${USERNAME} cli.js package.json ./
66+
COPY --from=builder --chown=${USERNAME}:${USERNAME} /app/lib /app/lib
67+
2168
# Run in headless and only with chromium (other browsers need more dependencies not included in this image)
22-
ENTRYPOINT ["node", "cli.js", "--headless", "--browser", "chromium"]
69+
ENTRYPOINT ["node", "cli.js", "--headless", "--browser", "chromium", "--no-sandbox"]

0 commit comments

Comments
 (0)