Closed Bug 922878 Opened 11 years ago Closed 11 years ago

Allow better browser detection

Categories

(Add-on SDK Graveyard :: General, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: irakli, Unassigned)

References

Details

At the moment add-on's targeting multiple browsers have no good way of detecting
weather target is firefox or not. For example 1Password used `(typeof ChromeWindow == "object")` expression that became invalid after Bug 899388 was fixed, causing regression reported under Bug 922141

SDK should provide a simple for add-ons to detect if target browser is firefox, or more precisely is addonSDK
How is this not covered by the system/xul-app module?
Blocks: 922141
Why isn't feature detection enough?
Why do content scripts need to know in which browser they're running?
Addon code (background.html in Chrome) should be enough to tell the content script which browser it's running on, no?
I think this should probably *not* be implemented even though our discussion about Bug 922141 was what prompted this bug report. 

(In reply to David Bruant from comment #2)
> Why isn't feature detection enough?
> Why do content scripts need to know in which browser they're running?

For 1Password at least, we have some scripts that are included in every browser's add-on/extension. They use some high level wrapper functions we wrote to abstract away the browser differences and use runtime conditionals to control the flow for the browser environment. This has proven to be a bit fragile in a few instances, and I'm considering how to decouple the need for this code to run in multiple browsers from the fragile browser detection approach we're currently using.

> Addon code (background.html in Chrome) should be enough to tell the content
> script which browser it's running on, no?

I think the proper way to do browser detection will be at build time by selectively including scripts for the different browsers such as adding an additional script reference in contentScripts page-mod parameters for Firefox that would not be referenced in Safari or Chrome. Setting an additional content script in Chrome's manifest and Safari's Info.plist (or the extension builder) is equally trivial. These scripts would define variables or functions to check the current browser.

For the add-on/global/background code, having the environment specified in the main.js file for Firefox and a dedicated script reference in Safari's global page or Chrome's manifest background scripts property would solve the issue in that scope.
(In reply to Jamie Phelps from comment #3)
> I think the proper way to do browser detection will be at build time by
> selectively including scripts for the different browsers 
oh shit, I hadn't thought of that (too biased by the web, I guess...). It's actually an excellent idea!
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.