Closed kripul closed 8 years ago
@kripul - Yes you can.
Here's an example: https://runkit.com/57700072b1bc291300690032/58028c2e82bd9d0014eef993
var random_useragent = require('random-useragent');
var result = random_useragent.getRandom((ua) => ua.deviceType === 'mobile');
console.log(result);
You can make the filter as specific or loose as you want (for instance, only returning iphones or androids, etc.
Change the getRandom()
to getRandomData()
to see what all is available.
Is avaible only for mobile? I try with 'desktop' give me null result.
@kripul - currently I'm using ua-parser-js to provide some extra info, so you can filter on data it returns. From that lib's readme: Possible 'device.type': console, mobile, tablet, smarttv, wearable, embedded
, so there is not "desktop" available.
I might add the data from the following lib as well: useragent-parser-js, but that would increase the size of my data file.
To better answer your question, all this library does is pick a random value from: https://github.com/skratchdot/random-useragent/blob/master/useragent-data.json
So you could write a filter that looks something like this:
randomUseragent.getRandom((ua) => {
return [
'/Browsers - Mac',
'/Browsers - Windows'
].indexOf(ua.folder) === 0
});
Cant I generate random UA for mobile?