www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit c55b3555488c2f3be8cbf53166208437bf966773
parent a4cd45ceb400ef742ce980e5331dca3e40625b8a
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 27 Apr 2018 01:37:38 -0400

Add "Firefox/[version]" to user agent

Some sites didn't render properly, both in snapshots and in Scaffold,
due to browser sniffing.

Diffstat:
Mchrome/content/zotero/xpcom/zotero.js | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -2606,13 +2606,26 @@ Zotero.VersionHeader = { observe: function (subject, topic, data) { try { - var channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel); - if (channel.URI.host.match(/zotero\.org$/)) { + // Add "Firefox/[version]" to the user agent before "Zotero/[version]" + let channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel); + let ua = channel.getRequestHeader('User-Agent'); + let info = Services.appinfo; + let pos = ua.indexOf(info.name + '/'); + ua = ua.slice(0, pos) + `Firefox/${info.platformVersion.match(/^\d+/)[0]}.0 ` + + ZOTERO_CONFIG.CLIENT_NAME + '/'; + // Send full Zotero version to zotero.org + if (channel.URI.host.endsWith(ZOTERO_CONFIG.DOMAIN_NAME)) { + ua += Zotero.version; channel.setRequestHeader("X-Zotero-Version", Zotero.version, false); } + // Otherwise only send major.minor version + else { + ua += Zotero.version.replace(/(\d+\.\d+).*/, '$1'); + } + channel.setRequestHeader('User-Agent', ua, false); } catch (e) { - Zotero.debug(e); + Zotero.debug(e, 1); } },