Skip to content

fix(extension): pass client name on token-bypass connect#41845

Open
cipheraxat wants to merge 2 commits into
microsoft:mainfrom
cipheraxat:fix-41839-extension-client-name
Open

fix(extension): pass client name on token-bypass connect#41845
cipheraxat wants to merge 2 commits into
microsoft:mainfrom
cipheraxat:fix-41839-extension-client-name

Conversation

@cipheraxat

Copy link
Copy Markdown

Summary

  • On the token-bypass connect path, handleConnectToTab was called in the same effect that called setClientInfo(info), so it still closed over the initial "unknown" client name.
  • Pass the freshly parsed client name into handleConnectToTab at that call site so the status page and tab group show the real MCP client name.
  • Extend the existing token-bypass extension test to assert Connected to "token-bypass-client" on the status page.

Fixes #41839

Test plan

  • npm run test-extension -- --grep "bypass connection" (chromium + legacy v1)
  • Full npm run test-extension suite (2 unrelated flaky tab tests failed once, passed on rerun; bypass tests passed)

Token-bypass called handleConnectToTab in the same effect as setClientInfo,
so the callback still closed over the initial "unknown" name. Pass the
parsed client name explicitly and assert it on the status page.
@dgozman
dgozman requested a review from yury-s July 17, 2026 13:38
Comment thread packages/extension/src/ui/connect.tsx Outdated
const handleConnectToTab = useCallback(async (tab?: chrome.tabs.Tab) => {
const handleConnectToTab = useCallback(async (tab?: chrome.tabs.Tab, clientNameOverride?: string) => {
setShowTabList(false);
const name = clientNameOverride ?? clientInfo;

@yury-s yury-s Jul 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a band-aid both of clientNameOverride and clientInfo are the same, so this is a workaround for the react stale closure bug.

The client name comes from window.location.search, which never changes for the lifetime of the page. Let's parse it once outside the component (or in a useMemo) and use it as a plain constant:

const clientInfo = (() => {
  try {
    return JSON.parse(new URLSearchParams(window.location.search).get('client') || '{}').name || 'unknown';
  } catch {
    return 'unknown';
  }
})();

Address review feedback: avoid a clientNameOverride workaround for the
React stale closure by treating the URL-derived client name as a module
constant, since it never changes for the page lifetime.
@cipheraxat

cipheraxat commented Jul 17, 2026

Copy link
Copy Markdown
Author

Updated @yury-s per review feedback: clientInfo is now parsed once from window.location.search as a module-level constant, and the clientNameOverride workaround is removed. Bypass connection tests still pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playwright Extension: client name always shows as "unknown" on the token-bypass connect path

2 participants