🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

browser-platform

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-platform

Naive browser/platform detection

1.0.0
latest
Source
npm
Version published
Weekly downloads
4
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

browser-platform

This is a naive implementation of browser/platform detection in JavaScript.

It is exported as a CommonJS/Node-style module, the main exports is a function that is meant to be called by passing in the useragent.

// CommonJS/Node Import
var platform = require('browser-platform')(window.navigator.userAgent)

// Direct browser injection
var platform = getBrowserPlatform(window.navigator.userAgent);
document.documentElement.setAttribute('class', ['js'].concat(platform.classNames).join(' '))

When run client-side some features (namely touch) are detected from the environment if not easily determined from the useragent. Android and iOS assume touch.

You can use platform.classes.join(' ') as CSS classes to be added to the html element, which can help with platform specific quirks.

The base portable detection portion of the script originated with detectmobilebrowser.com's regular expression(s). The rest was written by me. This library is released under a permissive ISC license. It has been very useful for me, and at 2.3KB minified and gzipped, much smaller than most detection libraries.

Keywords

browser

FAQs

Package last updated on 08 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts