From 711089d261fdb8571e11e378db561e66e9e2e396 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 22 Sep 2025 16:47:13 -0700 Subject: [PATCH] chore: add auth token example (#1070) Fixes https://github.com/microsoft/playwright-mcp/issues/1069 --- extension/src/ui/authToken.css | 72 ++++++++++++++++++++++++++++++++++ extension/src/ui/authToken.tsx | 54 ++++++++++++++++++++++++- extension/src/ui/icons.tsx | 6 +++ 3 files changed, 130 insertions(+), 2 deletions(-) diff --git a/extension/src/ui/authToken.css b/extension/src/ui/authToken.css index d44eb76..adfa30c 100644 --- a/extension/src/ui/authToken.css +++ b/extension/src/ui/authToken.css @@ -68,3 +68,75 @@ .auth-token-refresh:not(:disabled):hover { background-color: var(--color-btn-selected-bg); } + +.auth-token-example-section { + margin-top: 16px; +} + +.auth-token-example-toggle { + display: flex; + align-items: center; + gap: 8px; + background: none; + border: none; + padding: 8px 0; + font-size: 12px; + color: #656d76; + cursor: pointer; + outline: none; + text-align: left; + width: 100%; +} + +.auth-token-example-toggle:hover { + color: #1f2328; +} + +.auth-token-chevron { + display: inline-flex; + align-items: center; + justify-content: center; + transform: rotate(-90deg); + flex-shrink: 0; +} + +.auth-token-chevron.expanded { + transform: rotate(0deg); +} + +.auth-token-chevron svg { + width: 12px; + height: 12px; +} + +.auth-token-chevron .octicon { + margin: 0px; +} + +.auth-token-example-content { + margin-top: 12px; + padding: 12px 0; +} + +.auth-token-example-description { + font-size: 12px; + color: #656d76; + margin-bottom: 12px; +} + +.auth-token-example-config { + display: flex; + align-items: flex-start; + gap: 8px; + background-color: #ffffff; + padding: 12px; +} + +.auth-token-example-code { + font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; + font-size: 11px; + color: #1f2328; + white-space: pre; + flex: 1; + line-height: 1.4; +} diff --git a/extension/src/ui/authToken.tsx b/extension/src/ui/authToken.tsx index 7da55fb..699cf2f 100644 --- a/extension/src/ui/authToken.tsx +++ b/extension/src/ui/authToken.tsx @@ -21,6 +21,7 @@ import './authToken.css'; export const AuthTokenSection: React.FC<{}> = ({}) => { const [authToken, setAuthToken] = useState(getOrCreateAuthToken); + const [isExampleExpanded, setIsExampleExpanded] = useState(false); const onRegenerateToken = useCallback(() => { const newToken = generateAuthToken(); @@ -28,20 +29,69 @@ export const AuthTokenSection: React.FC<{}> = ({}) => { setAuthToken(newToken); }, []); + const toggleExample = useCallback(() => { + setIsExampleExpanded(!isExampleExpanded); + }, [isExampleExpanded]); + return (
Set this environment variable to bypass the connection dialog:
- PLAYWRIGHT_MCP_EXTENSION_TOKEN={authToken} + {authTokenCode(authToken)} - + +
+ +
+ + + {isExampleExpanded && ( +
+
+ Add this configuration to your MCP client (e.g., VS Code) to connect to the Playwright MCP Bridge: +
+
+ {exampleConfig(authToken)} + +
+
+ )}
); }; +function authTokenCode(authToken: string) { + return `PLAYWRIGHT_MCP_EXTENSION_TOKEN=${authToken}`; +} + +function exampleConfig(authToken: string) { + return `{ + "mcpServers": { + "playwright": { + "command": "npx", + "args": ["@playwright/mcp@latest", "--extension"], + "env": { + "PLAYWRIGHT_MCP_EXTENSION_TOKEN": + "${authToken}" + } + } + } +}`; +} + function generateAuthToken(): string { // Generate a cryptographically secure random token const array = new Uint8Array(32); diff --git a/extension/src/ui/icons.tsx b/extension/src/ui/icons.tsx index 04bd17d..fcf74b8 100644 --- a/extension/src/ui/icons.tsx +++ b/extension/src/ui/icons.tsx @@ -41,3 +41,9 @@ export const refresh = () => { ; }; + +export const chevronDown = () => { + return ; +};