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?
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:
if ("InstallTrigger" in window)
{
// Gecko platform, InstallTrigger available
InstallTrigger.install(InstallXPI);
}