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:
.gargoylesoftware.htmlunit.ScriptException: Wrapped
.gargoylesoftware.htmlunit.ScriptException: Wrapped
.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "InstallTrigger" is not defined.
Any idea about this?
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:
.gargoylesoftware.htmlunit.ScriptException: Wrapped
.gargoylesoftware.htmlunit.ScriptException: Wrapped
.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "InstallTrigger" is not defined.
Any idea about this?
Share Improve this question edited Feb 1, 2012 at 7:14 Wladimir Palant 57.7k12 gold badges99 silver badges127 bronze badges asked Feb 1, 2012 at 7:08 Prateek SharmaPrateek Sharma 3463 silver badges12 bronze badges1 Answer
Reset to default 7This 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).- User agent strings can be spoofed which is apparently what htmlunit is doing - it claims to be Firefox despite using a different browser engine. Your code will run into trouble then.
Here is how you would do it properly:
if ("InstallTrigger" in window)
{
// Gecko platform, InstallTrigger available
InstallTrigger.install(InstallXPI);
}