Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to initialize Stagehand: Cannot create proxy with a non-object as target or handler #41

Open
hackley opened this issue Apr 2, 2025 · 0 comments

Comments

@hackley
Copy link

hackley commented Apr 2, 2025

I'm trying to use the Stagehand MCP Server with a local browser on a Mac with Claude Desktop. I've tried a bunch of troubleshooting, including tweaking the config inside of index.js, but I haven't made any progress. Is this an error that people commonly run in to?

Later in the logs, I also get "Failed to navigate: Stagehand not initialized. Make sure to await stagehand.init() first."

In Claude Desktop, I see this:

User: navigate to amazon in my browser

Assistant: I'll navigate to Amazon's website for you.


View result from stagehand_navigate from stagehand (local)
{
  `url`: `https://www.amazon.com`
}
Failed to initialize Stagehand: Cannot create proxy with a non-object as target or handler

My logs in /Users/me/Code/mcp-server-browserbase/stagehand/logs/stagehand-2025-04-02.log show this:

[2025-04-02T03:01:51.577Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:01:51.577Z",
  "type": "ListResources",
  "params": {}
}
[2025-04-02T03:01:51.577Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:01:51.577Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-04-02T03:02:10.909Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:10.909Z",
  "type": "ListTools",
  "params": {}
}
[2025-04-02T03:02:10.910Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:10.910Z",
  "type": "ListTools",
  "response": {
    "tools": [
      {
        "name": "stagehand_navigate",
        "description": "Navigate to a URL in the browser. Only use this tool with URLs you're confident will work and stay up to date. Otheriwse use https://google.com as the starting point",
        "inputSchema": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "The URL to navigate to"
            }
          },
          "required": [
            "url"
          ]
        }
      },
      {
        "name": "stagehand_act",
        "description": "Performs an action on a web page element. Act actions should be as atomic and \n      specific as possible, i.e. \"Click the sign in button\" or \"Type 'hello' into the search input\". \n      AVOID actions that are more than one step, i.e. \"Order me pizza\" or \"Send an email to Paul \n      asking him to call me\". ",
        "inputSchema": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "description": "The action to perform. Should be as atomic and specific as possible, \n          i.e. 'Click the sign in button' or 'Type 'hello' into the search input'. AVOID actions that are more than one \n          step, i.e. 'Order me pizza' or 'Send an email to Paul asking him to call me'. The instruction should be just as specific as possible, \n          and have a strong correlation to the text on the page. If unsure, use observe before using act.\""
            },
            "variables": {
              "type": "object",
              "additionalProperties": true,
              "description": "Variables used in the action template. ONLY use variables if you're dealing \n            with sensitive data or dynamic content. For example, if you're logging in to a website, \n            you can use a variable for the password. When using variables, you MUST have the variable\n            key in the action template. For example: {\"action\": \"Fill in the password\", \"variables\": {\"password\": \"123456\"}}"
            }
          },
          "required": [
            "action"
          ]
        }
      },
      {
        "name": "stagehand_extract",
        "description": "Extracts structured data from the web page based on an instruction and a JSON schema (Zod schema). Extract works best for extracting TEXT in a structured format.",
        "inputSchema": {
          "type": "object",
          "description": "**Instructions for providing the schema:**\n  \n  - The `schema` should be a valid JSON Schema (Zod) object that defines the structure of the data to extract.\n  - Use standard JSON Schema syntax.\n  - The server will convert the JSON Schema to a Zod schema internally.\n  \n  **Example schemas:**\n  \n  1. **Extracting a list of search result titles:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"searchResults\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"type\": \"string\",\n          \"description\": \"Title of a search result\"\n        }\n      }\n    },\n    \"required\": [\"searchResults\"]\n  }\n  ```\n  \n  2. **Extracting product details:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": { \"type\": \"string\" },\n      \"price\": { \"type\": \"string\" },\n      \"rating\": { \"type\": \"number\" },\n      \"reviews\": {\n        \"type\": \"array\",\n        \"items\": { \"type\": \"string\" }\n      }\n    },\n    \"required\": [\"name\", \"price\", \"rating\", \"reviews\"]\n  }\n  ```\n  \n  **Example usage:**\n  \n  - **Instruction**: \"Extract the titles and URLs of the main search results, excluding any ads.\"\n  - **Schema**:\n    ```json\n    {\n      \"type\": \"object\",\n      \"properties\": {\n        \"results\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"title\": { \"type\": \"string\", \"description\": \"The title of the search result\" },\n              \"url\": { \"type\": \"string\", \"description\": \"The URL of the search result\" }\n            },\n            \"required\": [\"title\", \"url\"]\n          }\n        }\n      },\n      \"required\": [\"results\"]\n    }\n    ```\n  \n  **Note:**\n  \n  - Ensure the schema is valid JSON.\n  - Use standard JSON Schema types like `string`, `number`, `array`, `object`, etc.\n  - You can add descriptions to help clarify the expected data.\n  ",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Clear instruction for what data to extract from the page"
            },
            "schema": {
              "type": "object",
              "description": "A JSON Schema object defining the structure of data to extract",
              "additionalProperties": true
            }
          },
          "required": [
            "instruction",
            "schema"
          ]
        }
      },
      {
        "name": "stagehand_observe",
        "description": "Observes elements on the web page. Use this tool to observe elements that you can later use in an action. Use observe instead of extract when dealing with actionable (interactable) elements rather than text. More often than not, you'll want to use extract instead of observe when dealing with scraping or extracting structured text.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Instruction for observation (e.g., 'find the login button'). This instruction must be extremely specific."
            }
          },
          "required": [
            "instruction"
          ]
        }
      },
      {
        "name": "screenshot",
        "description": "Take a screenshot of the current page. Use this tool to learn where you are on the page when controlling the browser with Stagehand.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "fullPage": {
              "type": "boolean",
              "description": "Whether to take a screenshot of the full page (true) or just the visible viewport (false). Default is false."
            },
            "path": {
              "type": "string",
              "description": "Optional. Custom file path where the screenshot should be saved. If not provided, a default path will be used."
            }
          }
        }
      }
    ]
  }
}
[2025-04-02T03:02:11.318Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:11.318Z",
  "type": "ListResources",
  "params": {}
}
[2025-04-02T03:02:11.318Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:11.318Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-04-02T03:02:11.318Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:11.318Z",
  "type": "ListTools",
  "params": {}
}
[2025-04-02T03:02:11.318Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:11.318Z",
  "type": "ListTools",
  "response": {
    "tools": [
      {
        "name": "stagehand_navigate",
        "description": "Navigate to a URL in the browser. Only use this tool with URLs you're confident will work and stay up to date. Otheriwse use https://google.com as the starting point",
        "inputSchema": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "The URL to navigate to"
            }
          },
          "required": [
            "url"
          ]
        }
      },
      {
        "name": "stagehand_act",
        "description": "Performs an action on a web page element. Act actions should be as atomic and \n      specific as possible, i.e. \"Click the sign in button\" or \"Type 'hello' into the search input\". \n      AVOID actions that are more than one step, i.e. \"Order me pizza\" or \"Send an email to Paul \n      asking him to call me\". ",
        "inputSchema": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "description": "The action to perform. Should be as atomic and specific as possible, \n          i.e. 'Click the sign in button' or 'Type 'hello' into the search input'. AVOID actions that are more than one \n          step, i.e. 'Order me pizza' or 'Send an email to Paul asking him to call me'. The instruction should be just as specific as possible, \n          and have a strong correlation to the text on the page. If unsure, use observe before using act.\""
            },
            "variables": {
              "type": "object",
              "additionalProperties": true,
              "description": "Variables used in the action template. ONLY use variables if you're dealing \n            with sensitive data or dynamic content. For example, if you're logging in to a website, \n            you can use a variable for the password. When using variables, you MUST have the variable\n            key in the action template. For example: {\"action\": \"Fill in the password\", \"variables\": {\"password\": \"123456\"}}"
            }
          },
          "required": [
            "action"
          ]
        }
      },
      {
        "name": "stagehand_extract",
        "description": "Extracts structured data from the web page based on an instruction and a JSON schema (Zod schema). Extract works best for extracting TEXT in a structured format.",
        "inputSchema": {
          "type": "object",
          "description": "**Instructions for providing the schema:**\n  \n  - The `schema` should be a valid JSON Schema (Zod) object that defines the structure of the data to extract.\n  - Use standard JSON Schema syntax.\n  - The server will convert the JSON Schema to a Zod schema internally.\n  \n  **Example schemas:**\n  \n  1. **Extracting a list of search result titles:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"searchResults\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"type\": \"string\",\n          \"description\": \"Title of a search result\"\n        }\n      }\n    },\n    \"required\": [\"searchResults\"]\n  }\n  ```\n  \n  2. **Extracting product details:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": { \"type\": \"string\" },\n      \"price\": { \"type\": \"string\" },\n      \"rating\": { \"type\": \"number\" },\n      \"reviews\": {\n        \"type\": \"array\",\n        \"items\": { \"type\": \"string\" }\n      }\n    },\n    \"required\": [\"name\", \"price\", \"rating\", \"reviews\"]\n  }\n  ```\n  \n  **Example usage:**\n  \n  - **Instruction**: \"Extract the titles and URLs of the main search results, excluding any ads.\"\n  - **Schema**:\n    ```json\n    {\n      \"type\": \"object\",\n      \"properties\": {\n        \"results\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"title\": { \"type\": \"string\", \"description\": \"The title of the search result\" },\n              \"url\": { \"type\": \"string\", \"description\": \"The URL of the search result\" }\n            },\n            \"required\": [\"title\", \"url\"]\n          }\n        }\n      },\n      \"required\": [\"results\"]\n    }\n    ```\n  \n  **Note:**\n  \n  - Ensure the schema is valid JSON.\n  - Use standard JSON Schema types like `string`, `number`, `array`, `object`, etc.\n  - You can add descriptions to help clarify the expected data.\n  ",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Clear instruction for what data to extract from the page"
            },
            "schema": {
              "type": "object",
              "description": "A JSON Schema object defining the structure of data to extract",
              "additionalProperties": true
            }
          },
          "required": [
            "instruction",
            "schema"
          ]
        }
      },
      {
        "name": "stagehand_observe",
        "description": "Observes elements on the web page. Use this tool to observe elements that you can later use in an action. Use observe instead of extract when dealing with actionable (interactable) elements rather than text. More often than not, you'll want to use extract instead of observe when dealing with scraping or extracting structured text.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Instruction for observation (e.g., 'find the login button'). This instruction must be extremely specific."
            }
          },
          "required": [
            "instruction"
          ]
        }
      },
      {
        "name": "screenshot",
        "description": "Take a screenshot of the current page. Use this tool to learn where you are on the page when controlling the browser with Stagehand.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "fullPage": {
              "type": "boolean",
              "description": "Whether to take a screenshot of the full page (true) or just the visible viewport (false). Default is false."
            },
            "path": {
              "type": "string",
              "description": "Optional. Custom file path where the screenshot should be saved. If not provided, a default path will be used."
            }
          }
        }
      }
    ]
  }
}
[2025-04-02T03:02:11.848Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:11.848Z",
  "type": "ListResources",
  "params": {}
}
[2025-04-02T03:02:11.848Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:11.848Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-04-02T03:02:11.848Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:11.848Z",
  "type": "ListTools",
  "params": {}
}
[2025-04-02T03:02:11.848Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:11.848Z",
  "type": "ListTools",
  "response": {
    "tools": [
      {
        "name": "stagehand_navigate",
        "description": "Navigate to a URL in the browser. Only use this tool with URLs you're confident will work and stay up to date. Otheriwse use https://google.com as the starting point",
        "inputSchema": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "The URL to navigate to"
            }
          },
          "required": [
            "url"
          ]
        }
      },
      {
        "name": "stagehand_act",
        "description": "Performs an action on a web page element. Act actions should be as atomic and \n      specific as possible, i.e. \"Click the sign in button\" or \"Type 'hello' into the search input\". \n      AVOID actions that are more than one step, i.e. \"Order me pizza\" or \"Send an email to Paul \n      asking him to call me\". ",
        "inputSchema": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "description": "The action to perform. Should be as atomic and specific as possible, \n          i.e. 'Click the sign in button' or 'Type 'hello' into the search input'. AVOID actions that are more than one \n          step, i.e. 'Order me pizza' or 'Send an email to Paul asking him to call me'. The instruction should be just as specific as possible, \n          and have a strong correlation to the text on the page. If unsure, use observe before using act.\""
            },
            "variables": {
              "type": "object",
              "additionalProperties": true,
              "description": "Variables used in the action template. ONLY use variables if you're dealing \n            with sensitive data or dynamic content. For example, if you're logging in to a website, \n            you can use a variable for the password. When using variables, you MUST have the variable\n            key in the action template. For example: {\"action\": \"Fill in the password\", \"variables\": {\"password\": \"123456\"}}"
            }
          },
          "required": [
            "action"
          ]
        }
      },
      {
        "name": "stagehand_extract",
        "description": "Extracts structured data from the web page based on an instruction and a JSON schema (Zod schema). Extract works best for extracting TEXT in a structured format.",
        "inputSchema": {
          "type": "object",
          "description": "**Instructions for providing the schema:**\n  \n  - The `schema` should be a valid JSON Schema (Zod) object that defines the structure of the data to extract.\n  - Use standard JSON Schema syntax.\n  - The server will convert the JSON Schema to a Zod schema internally.\n  \n  **Example schemas:**\n  \n  1. **Extracting a list of search result titles:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"searchResults\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"type\": \"string\",\n          \"description\": \"Title of a search result\"\n        }\n      }\n    },\n    \"required\": [\"searchResults\"]\n  }\n  ```\n  \n  2. **Extracting product details:**\n  \n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": { \"type\": \"string\" },\n      \"price\": { \"type\": \"string\" },\n      \"rating\": { \"type\": \"number\" },\n      \"reviews\": {\n        \"type\": \"array\",\n        \"items\": { \"type\": \"string\" }\n      }\n    },\n    \"required\": [\"name\", \"price\", \"rating\", \"reviews\"]\n  }\n  ```\n  \n  **Example usage:**\n  \n  - **Instruction**: \"Extract the titles and URLs of the main search results, excluding any ads.\"\n  - **Schema**:\n    ```json\n    {\n      \"type\": \"object\",\n      \"properties\": {\n        \"results\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"title\": { \"type\": \"string\", \"description\": \"The title of the search result\" },\n              \"url\": { \"type\": \"string\", \"description\": \"The URL of the search result\" }\n            },\n            \"required\": [\"title\", \"url\"]\n          }\n        }\n      },\n      \"required\": [\"results\"]\n    }\n    ```\n  \n  **Note:**\n  \n  - Ensure the schema is valid JSON.\n  - Use standard JSON Schema types like `string`, `number`, `array`, `object`, etc.\n  - You can add descriptions to help clarify the expected data.\n  ",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Clear instruction for what data to extract from the page"
            },
            "schema": {
              "type": "object",
              "description": "A JSON Schema object defining the structure of data to extract",
              "additionalProperties": true
            }
          },
          "required": [
            "instruction",
            "schema"
          ]
        }
      },
      {
        "name": "stagehand_observe",
        "description": "Observes elements on the web page. Use this tool to observe elements that you can later use in an action. Use observe instead of extract when dealing with actionable (interactable) elements rather than text. More often than not, you'll want to use extract instead of observe when dealing with scraping or extracting structured text.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "instruction": {
              "type": "string",
              "description": "Instruction for observation (e.g., 'find the login button'). This instruction must be extremely specific."
            }
          },
          "required": [
            "instruction"
          ]
        }
      },
      {
        "name": "screenshot",
        "description": "Take a screenshot of the current page. Use this tool to learn where you are on the page when controlling the browser with Stagehand.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "fullPage": {
              "type": "boolean",
              "description": "Whether to take a screenshot of the full page (true) or just the visible viewport (false). Default is false."
            },
            "path": {
              "type": "string",
              "description": "Optional. Custom file path where the screenshot should be saved. If not provided, a default path will be used."
            }
          }
        }
      }
    ]
  }
}

[2025-04-02T03:02:23.783Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:23.783Z",
  "type": "CallTool",
  "params": {
    "name": "stagehand_navigate",
    "arguments": {
      "url": "https://www.amazon.com"
    }
  }
}
[2025-04-02T03:02:23.788Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:23.788Z",
  "type": "CallTool",
  "response": {
    "content": [
      {
        "type": "text",
        "text": "Failed to initialize Stagehand: Cannot create proxy with a non-object as target or handler"
      },
      {
        "type": "text",
        "text": "Operation logs:\n"
      }
    ],
    "isError": true
  }
}
[2025-04-02T03:02:25.694Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:25.694Z",
  "type": "ListResources",
  "params": {}
}
[2025-04-02T03:02:25.694Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:25.694Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-04-02T03:02:26.066Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:26.066Z",
  "type": "CallTool",
  "params": {
    "name": "stagehand_navigate",
    "arguments": {
      "url": "https://www.amazon.com"
    }
  }
}
[2025-04-02T03:02:26.066Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:26.066Z",
  "type": "CallTool",
  "response": {
    "content": [
      {
        "type": "text",
        "text": "Failed to navigate: Stagehand not initialized. Make sure to await stagehand.init() first."
      },
      {
        "type": "text",
        "text": "Operation logs:\n"
      }
    ],
    "isError": true
  }
}
[2025-04-02T03:02:27.970Z] [DEBUG] REQUEST: {
  "timestamp": "2025-04-02T03:02:27.970Z",
  "type": "CallTool",
  "params": {
    "name": "stagehand_navigate",
    "arguments": {
      "url": "https://google.com"
    }
  }
}
[2025-04-02T03:02:27.970Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-04-02T03:02:27.970Z",
  "type": "CallTool",
  "response": {
    "content": [
      {
        "type": "text",
        "text": "Failed to navigate: Stagehand not initialized. Make sure to await stagehand.init() first."
      },
      {
        "type": "text",
        "text": "Operation logs:\n"
      }
    ],
    "isError": true
  }
}

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

No branches or pull requests

1 participant