Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Browser, OS and device detection based on the available user agent string.
it's very rarely a good idea to use user agent sniffing. You can almost always find a better, more broadly compatible way to solve your problem! MDN: Browser detection using the user agent
In case some browser-specific issue cannot be fixed by applying the same code uniformly across the browsers we may need to do (sad gasp) some browser detection. For example, browser X crashes when function Y from library Z is used, so we have to detect when we are dealing with browser X and disable library Z.
Another legitimate case is when you need to know which browsers, os and devices are most frequently used by users of your site. Then you may want to send the data obtained via Sniffer to the server for further processing.
To install the library just use bower:
bower install sniffr
Ready to use library is available in the dist folder.
The library is meant to be used only in a browser, no server-side code is run. Include the library:
<script src="bower_components/dist/sniffr.min.js" />
after the page has loaded the object Sniffr
is available and can be used in the client code.
Example:
//If Windows and Firefox 28 or later
if (Sniffr.os.name === "windows"
&& Sniffr.browser.name === "firefox" && Sniffr.browser.version[0] >= 28) {
//Apply some workaround
}
Example:
//Sending user browser and os information to the server for further analysis
Stats.send(Sniffr.os, Sniffr.browser);
Sniffr.os
: operating system
Sniffr.browser
: browser
Sniffr.device
: device
Sniffr.sniff
: function that expects a user agent string as an argument, it is called automatically in a browser
Sniffr can also be used as a Node module in case you need to do some server-side user agent recognition as well.
First install it
npm install sniffr
Then load the module, provide it the agent string and query the results just like in a browser environment:
Some libraries like jQuery provide only browser information and not the OS information. Others like Detectizr are plugins for yet another libraries that you may not use. Yet others require some server-side code. Many libraries are usable only on the server side or only in a browser.
Sniffr provides simple and symmetric API, does not depend on other libraries, does not require the server part, is tiny, fast and easily extensible. In addition, it can be used both in a browser and on the server side.
The original sniffing dog image location is http://publicdomainvectors.org/en/free-clipart/Dog-sniffing-vector-image/11807.html
FAQs
Browser, os and device detection
The npm package sniffr receives a total of 22,259 weekly downloads. As such, sniffr popularity was classified as popular.
We found that sniffr 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.