{"record":{"id":"2c23553ccd422c1b","repo":"microsoft/playwright","slug":"unknown-method-method","errorCode":null,"errorMessage":"Unknown method: ${method}","messagePattern":"Unknown method: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/cli-daemon/daemon.ts","lineNumber":99,"sourceCode":"    const abortController = new AbortController();\n    connection.onclose = () => abortController.abort();\n    connection.onmessage = async message => {\n      const { id, method, params } = message;\n      try {\n        if (method === 'stop') {\n          await deleteSessionFile(clientInfo, sessionConfig);\n          const sendAck = async () => connection.send({ id, result: 'ok' }).catch(() => {});\n          if (options?.exitOnClose)\n            gracefullyProcessExitDoNotHang(0, () => sendAck());\n          else\n            await sendAck();\n        } else if (method === 'run') {\n          const { toolName, toolParams } = parseCliCommand(params.args);\n          toolParams._meta = { cwd: params.cwd, raw: params.raw || params.json, json: !!params.json };\n          const response = await backend.callTool(toolName, toolParams, abortController.signal);\n          await connection.send({ id, result: formatResult(response) });\n        } else {\n          throw new Error(`Unknown method: ${method}`);\n        }\n      } catch (e) {\n        const error = process.env.PWDEBUGIMPL ? (e as Error).stack || (e as Error).message : (e as Error).message;\n        connection.send({ id, error }).catch(() => {});\n      }\n    };\n  });\n\n  decorateServer(server);\n  browserContext.on('close', () => Promise.resolve().then(async () => {\n    await deleteSessionFile(clientInfo, sessionConfig);\n    if (options?.exitOnClose)\n      gracefullyProcessExitDoNotHang(0);\n  }));\n\n  await new Promise<void>((resolve, reject) => {\n    server.on('error', reject);\n    server.listen(socketPath, () => resolve());","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/cli-daemon/daemon.ts#L81-L117","documentation":"Thrown by the CLI daemon's socket message handler when the inbound `method` is neither `'stop'` nor `'run'`. The daemon protocol recognizes exactly two methods; any other value falls into the `else` branch and is rejected. The error is caught and sent back over the socket as the response error, not rethrown.","triggerScenarios":"A client (CLI client, test harness, or custom script) sends a JSON message whose `method` field is anything other than `\"stop\"` or `\"run\"` (e.g. `\"ping\"`, `\"list\"`, a typo like `\"runn\"`, or an undefined field due to a malformed payload).","commonSituations":"Version skew between the CLI client and daemon (client uses a method added in a newer version); a hand-rolled socket client sending the wrong frame shape; a test that sends raw JSON without going through the SocketConnection helper.","solutions":["Send only `method: \"run\"` (with `params.args`/`params.cwd`) or `method: \"stop\"`.","Verify the CLI client and daemon are the same Playwright version (a newer method is not supported by an older daemon).","Inspect the exact `method` string in the error to spot typos or undefined values caused by a malformed payload."],"exampleFix":"// before\nconnection.send({ id: 1, method: 'list', params: {} });\n// after\nconnection.send({ id: 1, method: 'run', params: { args: { _: ['screenshot'], target: 'ref' }, cwd: process.cwd() } });","handlingStrategy":"validation","validationCode":"const KNOWN_METHODS = new Set(['run', 'stop']);\nfunction buildFrame(id: number, method: string, params: any) {\n  if (!KNOWN_METHODS.has(method))\n    throw new TypeError(`Unsupported daemon method: ${method}`);\n  return { id, method, params };\n}","typeGuard":"type DaemonMethod = 'run' | 'stop';\nfunction isDaemonMethod(m: string): m is DaemonMethod {\n  return m === 'run' || m === 'stop';\n}","tryCatchPattern":null,"preventionTips":["Pin the CLI client and daemon to the same Playwright version.","Send only 'run' or 'stop'; gate outbound frames with a known-methods set.","When building a custom socket client, model the protocol as a literal-union type."],"tags":["daemon","protocol","input-validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}