Socket
Socket
Sign inDemoInstall

browser-platform

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    browser-platform

Naive browser/platform detection


Version published
Weekly downloads
4
decreased by-63.64%
Maintainers
1
Install size
15.6 kB
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 08 Feb 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc