Firefox macOS加载Native App时出现DataCloneError问题
Firefox Native Messaging连接报错排查(MacOS)
问题场景
在MacOS Ventura 13.5.1系统上开发Firefox Native Messaging扩展,参考MDN示例代码,当background.js仅包含一行代码:
let port = browser.runtime.connectNative("ping_pong");
加载扩展时触发以下错误:
DataCloneError: Exception object could not be cloned. subprocess_worker_common.js:203:15 onmessage resource://gre/modules/subprocess/subprocess_worker_common.js:203 NotSupportedError: ClonedErrorHolder constructor: We can only clone DOM Exceptions and native JS Error objects: onConnect/<@resource://gre/modules/NativeMessaging.sys.mjs:140:48 handler@resource://gre/modules/EventEmitter.sys.mjs:91:19 emit@resource://gre/modules/EventEmitter.sys.mjs:154:20 _cleanup@resource://gre/modules/NativeMessaging.sys.mjs:291:12 NativeApp/this.startupPromise<@resource://gre/modules/NativeMessaging.sys.mjs:116:14 EventEmitter.sys.mjs:158 undefined NativeMessaging.sys.mjs:115 startupPromise resource://gre/modules/NativeMessaging.sys.mjs:115
环境信息:Firefox 118.0.2(64位)、MacOS Ventura 13.5.1
排查与解决步骤
检查本地应用注册配置
确认ping_pong对应的manifest文件位置和内容:- MacOS上manifest需放在
~/Library/Application Support/Mozilla/NativeMessagingHosts/ping_pong.json或/Library/Application Support/Mozilla/NativeMessagingHosts/ping_pong.json; path字段必须是本地可执行文件的绝对路径,且文件具备执行权限(可通过chmod +x /path/to/your/app添加权限);allowed_extensions数组必须包含你的扩展ID,扩展ID可在Firefox扩展管理页面(about:debugging#/runtime/this-firefox)查看。
- MacOS上manifest需放在
添加错误监听获取具体原因
原代码未处理连接错误,导致底层异常无法直观展示。修改background.js:let port; try { port = browser.runtime.connectNative("ping_pong"); port.onDisconnect.addListener(() => { console.error("连接断开:", browser.runtime.lastError); }); } catch (err) { console.error("连接失败:", err); }通过扩展调试控制台(
about:debugging中点击扩展的"检查"按钮)查看具体错误,比如应用路径错误、权限不足、manifest格式无效等。验证本地应用的运行逻辑
- 确保本地应用能独立启动,无依赖缺失;
- 严格遵循Native Messaging协议:必须先发送4字节小端序的消息长度,再发送JSON格式的消息内容,即使是简单的ping/pong示例也需遵守。
测试版本兼容性
尝试升级Firefox到最新稳定版,或回退到117.x版本测试,确认是否为特定版本的bug。若升级后问题消失,说明是旧版本的已知问题。
内容的提问来源于stack exchange,提问作者jeffma
相关产品推荐
相关产品推荐

