“安装触发器”没有定义
在我的 html 页面中,我有类似这样的代码,其中仅当浏览器是 Firefox 时我才安装扩展:
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
//relevant code
InstallTrigger.install(InstallXPI);
}
它在每个浏览器中都可以正常工作。但是当通过 htmlunit 框架使用同一页面并在 webclient 中使用 browserversion.FIREFOX_3_6 参数时。它在那里显示一个错误:
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "InstallTrigger" is not defined.
对此有什么想法吗?
In my html page i have code something like this, where i have installed an extension only if the browser is Firefox:
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
//relevant code
InstallTrigger.install(InstallXPI);
}
It works fine in every browser. But when the same page is used through htmlunit framework and using browserversion.FIREFOX_3_6 argument in webclient. It shows an error there:
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "InstallTrigger" is not defined.
Any idea about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是给您的提醒:不要使用浏览器检测,使用功能检测。您的代码存在问题:
InstallTrigger
是 Gecko 引擎的功能,而不是 Firefox 的功能。然而,您在用户代理字符串中明确查找“Firefox”,并且可能会排除其他基于 Gecko 引擎的浏览器(例如 SeaMonkey、K-Meleon、Camino)。以下是正确的做法:
This is a reminder for you: don't use browser detection, use feature detection. The issues with your code:
InstallTrigger
is a feature of the Gecko engine, not Firefox. You are explicitly looking for "Firefox" in the user agent string however and might exclude other browsers based on the Gecko engine (there are e.g. SeaMonkey, K-Meleon, Camino).Here is how you would do it properly: