Skip to content

Latest commit

 

History

History
139 lines (105 loc) · 5.19 KB

File metadata and controls

139 lines (105 loc) · 5.19 KB
layout default
title Chapter 8: Troubleshooting, Security, and Contribution
nav_order 8
parent Playwright MCP Tutorial

Chapter 8: Troubleshooting, Security, and Contribution

Welcome to Chapter 8: Troubleshooting, Security, and Contribution. In this part of Playwright MCP Tutorial: Browser Automation for Coding Agents Through MCP, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.

This chapter covers practical troubleshooting and safe evolution of Playwright MCP usage.

Learning Goals

  • debug common runtime/setup issues quickly
  • apply safe defaults for credentials and browser state
  • understand upstream contribution and source layout
  • plan upgrades with minimal disruption

Troubleshooting Baseline

  1. verify host config syntax first
  2. validate browser install/runtime mode
  3. reproduce with minimal config and one deterministic action
  4. add capabilities and complex state incrementally

Source References

Summary

You now have an end-to-end operating model for integrating Playwright MCP into production coding-agent workflows.

Next steps:

  • standardize one baseline config per host used by your team
  • build one deterministic snapshot-first browser workflow and reuse it
  • audit session and credential handling before broad rollout

Source Code Walkthrough

packages/extension/src/ui/status.tsx

The ConnectionStatus interface in packages/extension/src/ui/status.tsx handles a key part of this chapter's functionality:

import { AuthTokenSection } from './authToken';

interface ConnectionStatus {
  isConnected: boolean;
  connectedTabId: number | null;
  connectedTab?: TabInfo;
}

const StatusApp: React.FC = () => {
  const [status, setStatus] = useState<ConnectionStatus>({
    isConnected: false,
    connectedTabId: null
  });

  useEffect(() => {
    void loadStatus();
  }, []);

  const loadStatus = async () => {
    // Get current connection status from background script
    const { connectedTabId } = await chrome.runtime.sendMessage({ type: 'getConnectionStatus' });
    if (connectedTabId) {
      const tab = await chrome.tabs.get(connectedTabId);
      setStatus({
        isConnected: true,
        connectedTabId,
        connectedTab: {
          id: tab.id!,
          windowId: tab.windowId!,
          title: tab.title!,
          url: tab.url!,
          favIconUrl: tab.favIconUrl

This interface is important because it defines how Playwright MCP Tutorial: Browser Automation for Coding Agents Through MCP implements the patterns covered in this chapter.

packages/extension/src/background.ts

The TabShareExtension class in packages/extension/src/background.ts handles a key part of this chapter's functionality:

};

class TabShareExtension {
  private _activeConnection: RelayConnection | undefined;
  private _connectedTabId: number | null = null;
  private _pendingTabSelection = new Map<number, { connection: RelayConnection, timerId?: number }>();

  constructor() {
    chrome.tabs.onRemoved.addListener(this._onTabRemoved.bind(this));
    chrome.tabs.onUpdated.addListener(this._onTabUpdated.bind(this));
    chrome.tabs.onActivated.addListener(this._onTabActivated.bind(this));
    chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
    chrome.action.onClicked.addListener(this._onActionClicked.bind(this));
  }

  // Promise-based message handling is not supported in Chrome: https://issues.chromium.org/issues/40753031
  private _onMessage(message: PageMessage, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) {
    switch (message.type) {
      case 'connectToMCPRelay':
        this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl).then(
            () => sendResponse({ success: true }),
            (error: any) => sendResponse({ success: false, error: error.message }));
        return true;
      case 'getTabs':
        this._getTabs().then(
            tabs => sendResponse({ success: true, tabs, currentTabId: sender.tab?.id }),
            (error: any) => sendResponse({ success: false, error: error.message }));
        return true;
      case 'connectToTab':
        const tabId = message.tabId || sender.tab?.id!;
        const windowId = message.windowId || sender.tab?.windowId!;
        this._connectTab(sender.tab!.id!, tabId, windowId, message.mcpRelayUrl!).then(

This class is important because it defines how Playwright MCP Tutorial: Browser Automation for Coding Agents Through MCP implements the patterns covered in this chapter.

How These Components Connect

flowchart TD
    A[ConnectionStatus]
    B[TabShareExtension]
    A --> B
Loading