How to use user-agents - 6 common examples

To help you get started, we’ve selected a few user-agents examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ayakashi-io / ayakashi / src / runner / runner.ts View on Github external
proxyUrl = config.config.proxyUrl;
    }
    let windowHeight;
    if (config.config && config.config.windowHeight) {
        windowHeight = config.config.windowHeight;
    }
    let windowWidth;
    if (config.config && config.config.windowWidth) {
        windowWidth = config.config.windowWidth;
    }
    let userAgent = "";
    if (!config.config || (config.config && (!config.config.userAgent || config.config.userAgent === "random"))) {
        userAgent = new UserAgent();
    }
    if (config.config && config.config.userAgent === "desktop") {
        userAgent = new UserAgent({deviceCategory: "desktop"});
    }
    if (config.config && config.config.userAgent === "mobile") {
        userAgent = new UserAgent({deviceCategory: "mobile"});
    }
    let protocolPort = 9730;
    if (config.config && config.config.protocolPort) {
        protocolPort = config.config.protocolPort;
    }
    let bridgePort = 9731;
    if (config.config && config.config.bridgePort) {
        bridgePort = config.config.bridgePort;
    }
    //spawn the chrome instance
    const headlessChrome = getInstance();
    await headlessChrome.init({
        headless: headless,
github browserslist / browserslist-useragent-regexp / src / useragentRegexp / useragentRegexp.spec.ts View on Github external
const userAgents = new Set();
	let data = null;

	for (const query of browsers) {

		const options = {
			browsers:            [query],
			allowHigherVersions: true
		};
		const versions = getBrowsersList(options);

		for (let i = 0; i < 30; i++) {

			try {
				data = new UserAgent(({ userAgent }) =>
					!userAgents.has(userAgent)
						&& mobile(userAgent, i)
						&& matchesUA(userAgent, options)
				);
			} catch (err) {
				continue;
			}

			userAgents.add(data.userAgent);
			yield {
				versions:  versions.map(_ => `${_.family} ${_.version.join('.')}`),
				userAgent: data.userAgent,
				query
			};
		}
	}
github ayakashi-io / ayakashi / src / sessionDb / userAgent.ts View on Github external
return (new UserAgent({
                deviceCategory: "mobile",
                platform: platform || "Linux armv8l"
            })).data;
        }
        if (agent === "chrome-desktop") {
            return (new UserAgent([
                /Chrome/,
                {
                    deviceCategory: "desktop",
                    platform: platform || "Win32"
                }
            ])).data;
        }
        if (agent === "chrome-mobile") {
            return (new UserAgent([
                /Chrome/,
                {
                    deviceCategory: "mobile",
                    platform: platform || "Linux armv8l"
                }
            ])).data;
        }

        //default to chrome-desktop
        return (new UserAgent([
            /Chrome/,
            {
                deviceCategory: "desktop",
                platform: platform || "Win32"
            }
        ])).data;
github ayakashi-io / ayakashi / src / sessionDb / userAgent.ts View on Github external
platform: EmulatorOptions["platform"] | undefined
): UserAgentDataType {
    try {
        if (agent === "random") {
            return (new UserAgent({
                platform: platform || "Win32"
            })).data;
        }
        if (agent === "desktop") {
            return (new UserAgent({
                deviceCategory: "desktop",
                platform: platform || "Win32"
            })).data;
        }
        if (agent === "mobile") {
            return (new UserAgent({
                deviceCategory: "mobile",
                platform: platform || "Linux armv8l"
            })).data;
        }
        if (agent === "chrome-desktop") {
            return (new UserAgent([
                /Chrome/,
                {
                    deviceCategory: "desktop",
                    platform: platform || "Win32"
                }
            ])).data;
        }
        if (agent === "chrome-mobile") {
            return (new UserAgent([
                /Chrome/,
github ayakashi-io / ayakashi / src / runner / runner.ts View on Github external
}
    let proxyUrl;
    if (config.config && config.config.proxyUrl) {
        proxyUrl = config.config.proxyUrl;
    }
    let windowHeight;
    if (config.config && config.config.windowHeight) {
        windowHeight = config.config.windowHeight;
    }
    let windowWidth;
    if (config.config && config.config.windowWidth) {
        windowWidth = config.config.windowWidth;
    }
    let userAgent = "";
    if (!config.config || (config.config && (!config.config.userAgent || config.config.userAgent === "random"))) {
        userAgent = new UserAgent();
    }
    if (config.config && config.config.userAgent === "desktop") {
        userAgent = new UserAgent({deviceCategory: "desktop"});
    }
    if (config.config && config.config.userAgent === "mobile") {
        userAgent = new UserAgent({deviceCategory: "mobile"});
    }
    let protocolPort = 9730;
    if (config.config && config.config.protocolPort) {
        protocolPort = config.config.protocolPort;
    }
    let bridgePort = 9731;
    if (config.config && config.config.bridgePort) {
        bridgePort = config.config.bridgePort;
    }
    //spawn the chrome instance
github Wildhoney / ReactCrossfilter / example / server / default.js View on Github external
var teamName = teamHtml.match(/<a href="\'.+?\'">(.+?)&lt;\/a&gt;&lt;\/td&gt;/i)[1],
                points   = teamHtml.match(/(\d+)&lt;\/td&gt;/i)[1];

            table.push({ name: teamName, points: parseInt(points) });

        });

        return table;

    }

    var options = {
        url: 'http://www.bbc.co.uk/sport/football/tables',
        headers: {
            'User-Agent': agents.random()
        }
    };

    request(options, function response(error, response, body) {

        if (!error &amp;&amp; response.statusCode == 200) {
            table = eplTable(body);
        }

    });

    app.get('/english-premier-league.json', function(request, response) {
        response.send(JSON.stringify(table));
    });

})(process);</a>

user-agents

A JavaScript library for generating random user agents.

BSD-2-Clause
Latest version published 2 days ago

Package Health Score

78 / 100
Full package analysis

Popular user-agents functions