Browser plugin: Don't rely on userAgent
Currently the browser plugin for Zotero relies on user agent sniffing for some features.
One side effect of that is, that if I'm debugging an unrelated website with Chrome's device simulator being active (which also modifies the user agent), I receive multiple errors in the developer console ("Uncaught ReferenceError: safari is not defined") generated by this extension.
An (additional) check whether `window.safari` is set would be way nicer - or even separate build configurations for separate browsers, in order to get completely rid of user agent sniffing.
Independently, thank you for your work!
One side effect of that is, that if I'm debugging an unrelated website with Chrome's device simulator being active (which also modifies the user agent), I receive multiple errors in the developer console ("Uncaught ReferenceError: safari is not defined") generated by this extension.
An (additional) check whether `window.safari` is set would be way nicer - or even separate build configurations for separate browsers, in order to get completely rid of user agent sniffing.
Independently, thank you for your work!
If you have suggestions for the browser detection code that are battle-tested then they are very welcome.
We could probably just set those lines in the build script — we have separate builds for Firefox, Chrome, and Safari. I've created an issue for this.
Having the Zotero extension installed, open an arbitrary website in Chrome. Press F12 to open the DevTools, press device simulation (Ctrl+Shift+M), choose for example iPhone X and reload the page. When reloading, three exceptions about `safari` being undefined appear.
> We could probably just set that isSafari line in the build script.
Yes, that was the idea. Or just check, whether `typeof safari !== 'undefined` at the following locations:
https://github.com/zotero/zotero-connectors/blob/718237a6bcc354b27a2a8db474f5275407b529ff/src/common/inject/progressWindow_inject.js#L68
https://github.com/zotero/zotero-connectors/blob/718237a6bcc354b27a2a8db474f5275407b529ff/src/common/inject/modalPrompt_inject.js#L47
https://github.com/zotero/zotero-connectors/blob/718237a6bcc354b27a2a8db474f5275407b529ff/src/common/inject/inject.jsx#L72