Problem
When an MCP client connects to the Playwright Extension via the token-bypass path (setting
PLAYWRIGHT_MCP_EXTENSION_TOKEN so the connection dialog doesn't need a manual click), the
connect page and the status page ("Connected to X") always show the client name as "unknown",
regardless of what name the client actually declares. The tab-picker connection path (clicking
"Allow & select") shows the real client name correctly.
Confirmed on upstream/main, unmodified - not specific to any fork or downstream change.
Root cause
In packages/extension/src/ui/connect.tsx, handleConnectToTab is a useCallback that reads the
client name from clientInfo React state:
const handleConnectToTab = useCallback(async (tab?: chrome.tabs.Tab) => {
...
clientName: clientInfo,
...
}, [clientInfo]);
On the token-bypass path, it's called synchronously within the same effect run that just called
setClientInfo(info):
const info = `${client.name || 'unknown'}`;
setClientInfo(info);
...
if (token === expectedToken) {
await handleConnectToTab(); // still closes over the initial 'unknown' clientInfo
return;
}
setClientInfo only schedules a re-render; it doesn't mutate the clientInfo variable already
captured by the version of handleConnectToTab this effect closed over at mount. So this call
always sees the initial 'unknown' state, never the freshly-parsed info. The tab-picker path
doesn't hit this, since a user click can only happen after at least one render has already landed
with the updated clientInfo.
This is deterministic (not a timing race) and independent of what client name is actually passed -
reproduces the same way regardless.
Proposed fix
Pass the freshly-parsed name explicitly as an argument at the token-bypass call site instead of
relying on the closure - e.g. give handleConnectToTab an optional second parameter and pass
info directly there, leaving the tab-picker call site (which doesn't have this problem) unchanged.
Small, isolated, single-file fix. Happy to open a PR if this approach sounds right.
Problem
When an MCP client connects to the Playwright Extension via the token-bypass path (setting
PLAYWRIGHT_MCP_EXTENSION_TOKENso the connection dialog doesn't need a manual click), theconnect page and the status page ("Connected to X") always show the client name as
"unknown",regardless of what name the client actually declares. The tab-picker connection path (clicking
"Allow & select") shows the real client name correctly.
Confirmed on
upstream/main, unmodified - not specific to any fork or downstream change.Root cause
In
packages/extension/src/ui/connect.tsx,handleConnectToTabis auseCallbackthat reads theclient name from
clientInfoReact state:On the token-bypass path, it's called synchronously within the same effect run that just called
setClientInfo(info):setClientInfoonly schedules a re-render; it doesn't mutate theclientInfovariable alreadycaptured by the version of
handleConnectToTabthis effect closed over at mount. So this callalways sees the initial
'unknown'state, never the freshly-parsedinfo. The tab-picker pathdoesn't hit this, since a user click can only happen after at least one render has already landed
with the updated
clientInfo.This is deterministic (not a timing race) and independent of what client name is actually passed -
reproduces the same way regardless.
Proposed fix
Pass the freshly-parsed name explicitly as an argument at the token-bypass call site instead of
relying on the closure - e.g. give
handleConnectToTaban optional second parameter and passinfodirectly there, leaving the tab-picker call site (which doesn't have this problem) unchanged.Small, isolated, single-file fix. Happy to open a PR if this approach sounds right.