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

如何配置Nightwatch.js结合geckodriver实现Firefox启动时预装MetaMask

修正后可正常加载扩展的完整配置

const path = require('path');
const pathToGeckoDriver = require('geckodriver').path;

module.exports = {
  src_folders: ['src/tests'],
  page_objects_path: ['src/pages'],
  custom_commands_path: ['src/custom-commands'],

  webdriver: {
    start_process: true,
    server_path: pathToGeckoDriver,
  },

  test_settings: {
    default: {
      launch_url: 'https://some-website.com',
      end_session_on_fail: false,
      desiredCapabilities: {
        browserName: 'firefox',
        acceptInsecureCerts: true,
        javascriptEnabled: true,
        // 火狐专属配置的键名必须为moz:firefoxOptions,是原配置出错的核心原因
        "moz:firefoxOptions": {
          // 建议先注释profile配置避免冲突,确认扩展加载正常后再按需启用
          // args: ['-profile', path.resolve(__dirname, 'nightwatch')], 
          add_extension: [
            // 必须传入XPI文件的绝对路径,相对路径geckodriver无法正确识别
            path.resolve(__dirname, 'metamask-10.2.2-an+fx.xpi')
          ],
        },
      },
    },
  },
};

核心修改说明

  • 配置键名修正:geckodriver要求火狐专属配置的键名为moz:firefoxOptions,此前使用的firefoxOptions属于无效写法,无法被驱动识别。
  • 路径统一处理:不管是扩展文件还是自定义火狐profile,都要通过path.resolve(__dirname, 相对路径)生成绝对路径传入,geckodriver不会基于配置文件所在目录解析相对路径。
  • 冲突规避:如果同时使用自定义profile和add_extension,要确保profile中没有预装不同版本的MetaMask,否则会出现加载冲突,建议先注释掉profile相关配置,确认扩展可以正常加载后再按需调整。

常见异常排查

  • 确认下载的MetaMask XPI版本和本地安装的Firefox浏览器版本兼容,版本不匹配会导致扩展静默安装失败。
  • 确认geckodriver版本和Firefox版本匹配,大版本差异过大也会导致配置不生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 08:06:02