Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
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
user-agent
it will use navigator.userAgent
.
Returns true if the given node.js http request comes with a mobile user agent header.
Example:
var http = require('http');
var mobile = require('is-mobile');
var server = http.createServer(function (req, res) {
res.end(mobile(req));
});
server.listen(8000);
With npm do:
npm install is-mobile
Bundle for the browser with browserify.
Taken from detectmobilebrowsers.com.
(MIT)
Copyright (c) 2013 Julian Gruber <julian@wayla.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 255,051 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.