Get Dynamic Web TWAIN Ready for Chrome User-Agent String Phase-Out
Google has announced that the good old user-agent string will be deprecated in the Chrome browser later this year. This change will provide better monitoring abilities, and let people know who is using this information and ultimately improve the end-users’ privacy. It is worth noting that this phase-out is currently considered experimental and its implementation may change in the next versions of Chrome. It’s important to be aware of the upcoming changes and learn how it might affect your web application.
What is User-Agent
User Agent (UA) is a string that contains information and details about the client’s browser and the platform it’s running on. UA is included in every request which gets sent by the browser and dependent on by many sites in various ways and for various purposes. Web applications use it in order to serve the clients the relevant site format, how it’s optimized for desktop or mobile devices, and to customize the page content according to the client’s browser and more.
What has Changed
Google plans to reduce the information that will be stored in the UA string gradually over the next year. Keep in mind that Google will not stop or block the ability to track and collect the end-user browser and platform information, but it will make it safer and easier to track. The phase-out will happen gradually over the next year.
How to Prepare for the Change
The web development is complex and it changes quickly which requires developers to keep posted to the latest updates. Luckily, we are here to help you navigate the ever-changing web environment and be prepared to adapt to those changes.
One of Dynamsoft’s products, the SDK Dynamic Web TWAIN, makes use of the user-agent string to perform runtime environment detection and this change will have some impact on this library.
For future Chrome versions, we will check for the existence of the new API userAgentData. If userAgentData doesn’t exist, which indicates the browser still uses the good old userAgent API, the library continues down the old route the same way as before. Otherwise, we use userAgentData for environment detection in a new workflow as follows.
First, we use the following line of code to determine whether the browser is running on mobile devices:
Next, we use the following lines of code to get the browser name and version:
var _browser = navigator.userAgentData.uaList.brand.toLowerCase();
var _browserVersion = navigator.userAgentData.uaList.version;
At last, we use the following code snippet to get the operating system information:
var _platform = highEntData.platform.toLowerCase();
var _platformVersion = highEntData.platformVersion;
var _architecture = highEntData.architecture.toLowerCase();
With the implementation above, we ensure that the library will continue to work as expected in both future versions of Chrome and the current/old versions of Chrome. We will continue to monitor Google’s new implementation and update this article as new changes occur.
If you have any questions or comments, please contact us at firstname.lastname@example.org