You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中npx playwright codegen无法运行及相关问题求助

解决Playwright Codegen的两个问题:VS Code终端TargetClosedError及无TypeScript选项

一、VS Code终端执行npx playwright codegen报TargetClosedError的解决办法

  • 核对环境变量差异:在VS Code终端执行echo %PATH%,和CMD里执行同命令的结果对比,把缺失的浏览器路径(比如Chrome、Edge的安装目录)添加到系统环境变量,重启VS Code后重试命令。
  • 关闭终端集成:打开VS Code设置,搜索terminal.integrated.shellIntegration.enabled,设为false,重启终端再运行npx playwright codegen。
  • 强制指定浏览器:执行npx playwright codegen --browser chrome(或firefox/edge),明确指定启动的浏览器,避免自动检测异常。
  • 重装浏览器依赖:执行npx playwright install --force,强制重新安装Playwright对应的浏览器驱动,清理损坏的缓存文件。

二、Playwright Inspector Target下拉无TypeScript选项的解决办法

  • 初始化TypeScript项目:在项目根目录执行npm init playwright@latest,选择TypeScript作为生成代码的语言,自动创建tsconfig.json和相关配置。如果已有项目,手动添加基础tsconfig.json:
    {
      "compilerOptions": {
        "target": "ESNext",
        "module": "commonjs",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true
      }
    }
    
  • 启动时指定语言:在CMD中执行npx playwright codegen --target typescript,强制指定输出TypeScript代码,此时Inspector的Target下拉会显示TypeScript选项。
  • 升级Playwright版本:执行npx playwright --version查看当前版本,若不是最新稳定版,执行npm install -D @playwright/test@latest升级,旧版本可能存在UI选项缺失的bug。

内容的提问来源于stack exchange,提问作者Anna Boekestyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 16:12:03