What is the best way to handle unsupported browsers in Dart?

Dart is not supported in some browsers, especially in some mobile browsers, such as the Android browser. Instead of popping up, I would like to show the message "not supported".

So, we have a JS that generates a DIV with the message “not supported” if it detects supposedly unsupported devices:

var ua = navigator.userAgent.toLowerCase();

// Android 1-4
if (/android [1-4]/i.test(ua)) {
  window.document.querySelector('#mobile-not-supported').style.display = '';
  window.document.querySelector('#application-root-container').style.display = 'none';
}

The problem is that this is shown for some devices where it really works. For example, on some Android devices, it works in the Chrome browser, and not in the browser.

What is the best approach here? I'm not even sure about the strict list of supported browsers (there is only this: https://www.dartlang.org/support/faq.html#q-what-browsers-do-you-support-as-javascript-compilation-targets ) . Ideally, it is possible for JS to detect that some aspect of the application is not working, and only show the message “not supported” in these cases.

+4
source share
1 answer

My improved solution was to search for my own Android specifically in the user agent string.

var ua = navigator.userAgent.toLowerCase();

// Look for native Android browser, which Dart does not support.
var is_android = ((ua.indexOf('mozilla/5.0') > -1 && ua.indexOf('android ') > -1 &&    ua.indexOf('applewebkit') > -1) && !(ua.indexOf('chrome') > -1));
if (is_android) {
  window.document.querySelector('#mobile-not-supported').style.display = '';
  window.document.querySelector('#application-root-container').style.display = 'none';
}

In the future, I can try using the supported@caffinatedmonkey property .

0
source

Source: https://habr.com/ru/post/1534920/


All Articles