Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
The is-mobile npm package is a lightweight utility that helps in detecting if a user is accessing a website from a mobile device. It can be used to tailor user experiences based on the type of device being used.
Basic Mobile Detection
This feature allows you to detect if the user is accessing the website from a mobile device. The function returns a boolean value.
const isMobile = require('is-mobile');
if (isMobile()) {
console.log('User is on a mobile device');
} else {
console.log('User is not on a mobile device');
}
Custom User-Agent String
This feature allows you to pass a custom User-Agent string to the isMobile function to determine if it corresponds to a mobile device.
const isMobile = require('is-mobile');
const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1';
if (isMobile({ ua: userAgent })) {
console.log('User-Agent indicates a mobile device');
} else {
console.log('User-Agent does not indicate a mobile device');
}
Custom HTTP Headers
This feature allows you to pass custom HTTP headers to the isMobile function to determine if they indicate a mobile device.
const isMobile = require('is-mobile');
const headers = { 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1' };
if (isMobile({ headers })) {
console.log('HTTP headers indicate a mobile device');
} else {
console.log('HTTP headers do not indicate a mobile device');
}
The mobile-detect package provides more detailed information about the device, including the type of mobile device, operating system, and user-agent. It offers more granular control compared to is-mobile.
The detect-mobile-browser package is another lightweight utility for detecting mobile browsers. It is similar to is-mobile but offers fewer customization options.
The ua-parser-js package is a comprehensive library for parsing user-agent strings. It provides detailed information about the browser, engine, OS, and device, making it more versatile than is-mobile.
Check if mobile browser, based on useragent string.
var mobile = require('is-mobile');
console.log(mobile());
// => false
Returns true if a mobile browser is being used.
If you don't specify opts.ua
it will use navigator.userAgent
.
To add support for tablets, set tablet: true
.
To enable feature detection (i.e. namely for iPad with iOS 13), set featureDetect: true
and tablet: true
. This will only work in browser environments.
opts.ua
can also be an instance of a node.js http request, in which
case it will read the user agent header.
Example:
var http = require('http');
var mobile = require('is-mobile');
var server = http.createServer(function (req, res) {
res.end(mobile({ ua: req }));
});
server.listen(8000);
With npm do:
npm install is-mobile
Bundle for the browser with browserify.
Taken from detectmobilebrowsers.com.
Armv7l support added by @antongolub.
(MIT)
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Check if mobile browser.
The npm package is-mobile receives a total of 353,421 weekly downloads. As such, is-mobile popularity was classified as popular.
We found that is-mobile demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.