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

Playwright中WebKit浏览器无法运行测试的问题求助

解决Playwright中WebKit启动失败的问题

问题分析

报错browserType.launch: Target page, context or browser has been closed伴随符号查找错误,本质是Snap环境下的libpthread.so.0与Playwright自带WebKit依赖的GLIBC版本不兼容,Snap核心库覆盖系统库引发冲突。

解决方案

  • 强制使用系统原生库
    运行Playwright时通过环境变量指定优先加载系统的libpthread.so.0,避开Snap提供的版本:

    LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 npx playwright test --webkit
    

    也可在测试脚本中直接设置:

    process.env.LD_PRELOAD = '/lib/x86_64-linux-gnu/libpthread.so.0';
    const { test, expect } = require('@playwright/test');
    // 你的测试代码逻辑
    
  • 脱离Snap环境运行
    若当前Node.js是通过Snap安装,改用系统包管理器(如apt、dnf)或nvm安装Node.js,彻底规避Snap的库冲突。

  • 清理缓存后重装WebKit
    删除现有WebKit缓存文件,再重新安装对应依赖:

    rm -rf ~/.cache/ms-playwright/webkit-1983
    npx playwright install webkit
    

验证操作

执行修复后,单独运行WebKit测试用例确认恢复正常:

npx playwright test --project=webkit

内容的提问来源于stack exchange,提问作者anush Avanesyan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 21:04:53