detect Browser and OS details using Playwright

Playwright is a Node library to automate Chromium, Firefox, and WebKit with a single API. As Playwright has already reached its stable version, it is a high time to re-think the possibilities of introducing it in your end-to-end test automation journey. Talking about automation, quite often you need to detect the browser and OS settings on the go to handle different logics for different browser settings. Let’s see how you can detect the settings run time.

Basically you need to fetch userAgent information from the executor machine.

ua-parser-js is a JavaScript-based User-Agent string parser. You need to add it as a dependency in your project.

npm i --save-dev ua-parser-js

Now, simply you can fetch the user agent information like:

const uaParser = require('ua-parser-js');const getUA = await page.evaluate(() => navigator.userAgent);const userAgentInfo= uaParser(ua);// get browser nameconsole.log(userAgentInfo.browser.name);

You can now parse the userAgentInfo to fetch browser and OS information. Below script will give you an idea.

--

--

--

Tech Lead Manager @Postman 🚀 | Space Movie Lover 🪐 | Coder 👨‍💻 | Traveller ⛰️

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Journey as a developer

Exploring Angular 6

3 Daily Hurdles in the IT Industry

LocalStorage in Vue.js(Angular to Vue.js -Part 10)

Fetch data in React using Hooks

Skill-up RxJs: Project Euler 1–3

Building A Localised Places Autocomplete with Vue.js, Tailwind, and Google Places API

On connecting my app to the HackerNews Firebase API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinaba Ghosh

Abhinaba Ghosh

Tech Lead Manager @Postman 🚀 | Space Movie Lover 🪐 | Coder 👨‍💻 | Traveller ⛰️

More from Medium

How We Migrate Legacy Authentication OAuth 1.0 Using JWT And Redis

Build the Event Driven Application using Async API make it consistent using Cloud Event.

Deploying a nodeJS Application on Azure App Service using ACR

What are Microservices ?