Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
cerebral-module-useragent
Advanced tools
Adds useragent specs to your cerebral state model
A Cerebral module for everything user agent.
npm install --save cerebral-module-useragent
import controller from './controller'
import Useragent from 'cerebral-module-useragent'
const useragent = Useragent({
media: {
small: '(min-width: 600px)',
medium: '(min-width: 1024px)',
large: '(min-width: 1440px)',
portrait: '(orientation: portrait)'
}
})
controller.addModules({
useragent
})
The module exposes all the user agent information in your state model.
{
"useragent": {
"browser": {
"major": "48",
"name": "Chrome",
"version": "48.0.2564.97"
},
"device": {
"model": "",
"type": "",
"vendor": ""
},
"os": {
"name": "Mac OS X",
"version": "10.11.3"
},
"window": {
"width": 1920,
"height": 1080,
"orientation": "landscape"
},
"media": {
"small": true,
"medium": true,
"large": false,
"portrait": false
},
"network": {
"offline": false
},
"feature": {
"deviceMotion":true,
"contextMenu":false,
"serviceWorker":true,
"touch":false,
"geolocation":true
}
}
}
import controller from './controller'
import Useragent from 'cerebral-module-useragent'
const useragent = Useragent({
feature: true, // store all feature tests in state
parse: {
browser: true, // parse useragent.browser from ua string
device: true, // parse useragent.device from ua string
os: true // parse useragent.os from ua string
},
offline: { // check the docs at: https://github.com/HubSpot/offline#advanced
checkOnLoad: false,
interceptRequests: true,
reconnect: {
initialDelay: 3,
delay: 1.5
},
requests: false
},
window: true // update window size on resize
})
controller.addModules({
useragent
})
Those are the defaults - you can selectively disable any of these features.
By default there won't be any media queries. You have to define them from scratch.
I am using the ua-parser-js package to parse navigator.userAgent
. Currently only the browser, device and OS parts are stored in the model, because I didn't see any use for cpu and engine.
The window resize event is just slightly throttled using requestAnimationFrame()
. I might make this configurable to use a stronger throttle timeout if it proofs to be too resource hungry.
The media queries are tested with matchMedia()
so you should be able to use any valid CSS media query.
I am using the feature.js package to detect browser features. Please checkout the website to see a list of all supported feature tests.
You can also only store certain test results in the model or define your own tests.
const useragent = Useragent({
feature: {
touch: true,
serviceWorker: true,
getUserMedia: () => !!navigator.getUserMedia
}
})
All tests from
feature.js
are executed even if you set the feature option to false. This is a limitation of the library.
I am using the offline-js package to detect internet connectivity. The application is initially assumed to be online.
Fork repo
npm install
cd demo
and npm install
npm start
runs the demo which is currently used for testingnpm lint
lint with JavaScript Standard Stylenpm run build
compiles es6 to es5No tests yet. Feel free to issue a pull request if you want this.
FAQs
Adds useragent specs to your cerebral state model
The npm package cerebral-module-useragent receives a total of 0 weekly downloads. As such, cerebral-module-useragent popularity was classified as not popular.
We found that cerebral-module-useragent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.