NOtherDev / whatwebcando

An overview of the device integration HTML5 APIs
https://whatwebcando.today/
MIT License
836 stars 61 forks source link

JS TypeError breaks app usage. #53

Closed aargiriou closed 5 years ago

aargiriou commented 5 years ago

This is the error thrown: Uncaught TypeError: Cannot read property 'toUpperCase' of undefined

It seems that when the navigator.language is something like "el" instead of "el-GR", creates a bug in the method:

let fetchCaniuseBrowserUsage = memoize(() => {
    const locale = (navigator.languages && navigator.languages[0]) || navigator.language || 'en-US';
    const [, countryCode] = locale.split('-');
    return fetch(`https://cdn.jsdelivr.net/gh/Fyrd/caniuse/region-usage-json/${countryCode.toUpperCase()}.json`)
      .then(result => handleFetchErrors(result))
      .then(result => result.json())
      .then(data => new CaniuseBrowserUsage(data));
  });

In file https://github.com/NOtherDev/whatwebcando/blob/master/app/scripts/caniuse.js.

Will try to use the "GR" from "el-GR", where in this case it doesn't exist..

NOtherDev commented 5 years ago

Thanks a lot, @anaconda86!