faisalman / ua-parser-js

"Unmask Your Traffic" - UAParser.js: The Essential Web Development Tool for User-Agent Detection
https://uaparser.dev/
GNU Affero General Public License v3.0
9.28k stars 1.2k forks source link

feat: add Klarna Shopping Browser UA parser #669

Closed darasus closed 1 year ago

darasus commented 1 year ago

Klarna App with 150 million users is rather popular shopping browser.

Adding support for Klarna UA parser.

darasus commented 1 year ago

@faisalman hm but Klarna app is positioned as Shopping Browser, it has URL address bar etc. Attached a screenshot of how it looks. Would that still count as non browser?

IMG_B39C6BA29679-1

darasus commented 1 year ago

Hey @faisalman, thanks for merging this PR! Is this going to v1 or v2?

faisalman commented 1 year ago

v2, but might as well backported to v1 later

darasus commented 1 year ago

@faisalman how can we add this to v1?

faisalman commented 1 year ago

In the mean time, you can pass it as an extension when instantiating UAParser

const browsers = [
    [/(klarna)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
];
const parser = new UAParser({ browser: browsers });

const ua = 'Mozilla/5.0 (Linux; Android 12; moto g(60)s Build/S3RLS32.114-25-13; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Klarna/23.36.215';

uap.setUA(ua).getBrowser(); // { name: 'Klarna', version: '23.36.215', major: '23'} 

More details at https://docs.uaparser.js.org/v2/intro/extending-regex.html