Repository: mozilla/send
File: frontend/src/common.js (JavaScript)

Code before:
  an: 'Firefox Send',
  ds: 'web',
  tid: window.trackerId
});

const isSender = !location.pathname.includes('/download');

gcmCompliant().catch(err => {
  sendEvent(isSender ? 'sender' : 'recipient', 'unsupported', {
    cd6: err
  })
  window.location.replace('/unsupported/gcm');
});

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
    parseInt(navigator.userAgent.toLowerCase().match(/firefox\/*([^\n\r]*)\./)[1]) <= 49) {
  sendEvent(isSender ? 'sender' : 'recipient', 'unsupported', {
    cd6: new Error('Firefox is outdated.')
  })
  location.replace('/unsupported/outdated');
}

if (navigator.userAgent.toLowerCase().indexOf('msie') > -1 ||
    navigator.userAgent.toLowerCase().match(/trident\/7\./)) {
  window.location.replace('/unsupported/ie');
}


Review comment (suggestion):
Before we go too far down a UA+regex abyss, not sure if we want to consider something like https://github.com/faisalman/ua-parser-js maybe.
https://www.npmjs.com/package/ua-parser-js#using-jqueryzepto-ua

```js
const UAParser = require('ua-parser-js');
const parser = new UAParser();
const uaBrowser = parser.getResult().browser;

console.log(uaBrowser); // { name: "Firefox", version: "55.0", major: "55" }
```

---

**UPDATE:** A bit more verbose than I was hoping for, but it reads OK-ish. Pseudo-code ahoy!

```js
const UAParser = require('ua-parser-js');
const uaBrowser = new UAParser().getResult().browser;
const isSender = !location.pathname.includes('/download');
const senderOrRecipient = isSender ? 'sender' : 'recipient';

gcmCompliant().catch(err => {
  sendEvent(senderOrRecipient, 'unsupported', {
    cd6: err
  })
  window.location.replace('/unsupported/gcm');
});

checkUserAgent(uaBrowser, senderOrRecipient);

function checkUserAgent(browser, type) {
  const majorVersion = parseInt(browser.major, 10);
  switch (browser.name.toLowerCase()) {
    case 'firefox':
      if (majorVersion <= 49) {
        sendEvent(type, 'unsupported', {
          cd6: new Error('Firefox is outdated.')
        });
        location.replace('/unsupported/outdated');
        return;
      }
      break;

    case 'explorer': // NOTE: I made this value up.
      location.replace('/unsupported/ie');
      break;
  }
}
```

Code after:
window.Raven = require('raven-js');
window.Raven.config(window.dsn).install();
window.dsn = undefined;

const testPilotGA = require('testpilot-ga');
const {gcmCompliant, sendEvent} = require('./utils');
window.analytics = new testPilotGA({
  an: 'Firefox Send',
  ds: 'web',
  tid: window.trackerId
});

const isSender = !location.pathname.includes('/download');

gcmCompliant().catch(err => {
  sendEvent(isSender ? 'sender' : 'recipient', 'unsupported', {
    cd6: err
  }).then(() => {
    location.replace('/unsupported/gcm');
  });
});

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
    parseInt(navigator.userAgent.toLowerCase().match(/firefox\/*([^\n\r]*)\./)[1]) <= 49) {
    sendEvent(isSender ? 'sender' : 'recipient', 'unsupported', {
      cd6: new Error('Firefox is outdated.')
    }).then(() => {
      location.replace('/unsupported/outdated');
    });
}