npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

omegle-crawler-node

v1.0.10

Published

Node library to connect to and interact with Omegle's website.

Downloads

5

Readme

omegle-crawler-node

Node library to connect to and interact with the Omegle website. This library includes support for captcha solving, as well as video chat. This library is using puppeteer and is therefore using an instance of chromium to access Omegle exactly as a browser.

Getting started

Installation

To use omegle-node-crawler in your project, run:

npm i omegle-node-crawler

or

yarn add omegle-node-crawler

Usage

This library uses an event-based mechanism. Start by binding your functions to the possible events and then start a conversation. All the events and methods are available in the documentation section below.

Crawler example usage:

import { Handler } from "omegle-crawler-node";

const handler = new Handler({ headless: false });

handler.onConnected(() => handler.sendMessage("Hello."));
handler.onDisconnected(() => console.log("Disconnected"));
handler.onCaptcha(() => console.log("Captcha found"));

handler.startConversation("text");
handler.sendMessage("Hello");

Usage with video

This library allows for video chat. In order to use video chat, you must provide a valid video file in the format .y4m so that Chromium may read it. More information about this format and how to create files that work can be found here.

The path to the video file must be absolute.

Here is an example of using video chat:

import { Handler } from "omegle-crawler-node";

const handler = new Handler();

handler.onConnected(() => handler.sendMessage("Hello."));
handler.onDisconnected(() => console.log("Disconnected"));
handler.onCaptcha(captchaIdentifier => console.log("Captcha found", captchaIdentifier));

handler.startConversation("video", __dirname + "/video.y4m");
handler.sendMessage("Hello"); // __dirname returns the path of the current directory.

Documentation

Instanciation

Each instance of Handler is independant, allowing you to have multiple crawlers running at the same time. Keep in mind that the most crawlers are running, the highter the chance that Omegle detects you're a bot and flags you, increasing your captcha rate and the chance to get IP banned.

Create a new instance using the new keyword:

new Handler(options)

The options are puppeteer options, and can therefore be found on their API page. Some of them are overriden when trying to use the video: --use-fake-ui-for-media-stream, --use-fake-device-for-media-stream, --use-file-for-fake-video-capture=${videoPath}

Example:

const handler = new Handler();

Events

Here are listed all the events that can be triggered by this library.

onConnected(event: () => any)

Triggered when the instance has connected to a stranger.

Example:

handler.onConnected(() => console.log("Connected to stranger!"));

onDisconnected(event: () => any)

Triggered when the instance has been disconnected from the stranger.

Example:

handler.onDisconnected(() => console.log("Disconnected from stranger!"));

onCaptcha(even: (captchaID: string) => any)

Triggered when the instance has received a captcha.

Example:

handler.onCaptcha(captchaID => console.log("Captcha detected", captchaID));

onMessageReceived(event: (message: string) => any)

Triggered when the stranger has sent a message

Example:

handler.onMessageReceived(message => console.log("Message received:", message));

onInformation(event: (information: string) => any)

Triggered when an information was printed on screen.

Example of information messages: "Omegle couldn't find someone with the same interests".

Example:

handler.onInformation(information => console.log("Received information", information));

onError(event: (error: string) => any)

Triggered when the instance has received an error.

The error "Connection to server blocked." means you have been IP blocked by Omegle. This usually happens if you're connecting from a server based on a platform such as Azure or AWS.

Example:

handler.onError(error => console.log("Received error", error));

onMessageSent(event: (message: string) => any)

Triggered when the instance successfully sent a message.

Example:

handler.onConnected(message => console.log("Script sent message", message));

onUnexpectedToken(event: (unexpectedToken: string) => any)

Triggered when the instance has received an unexpected token.

Example:

handler.onConnected(unexpectedToken => console.log("Unexpected token!", unexpectedToken));

Methods

Methods you can call on your Handler instance

startConversation(conversationType: "text" | "video" [,options])

Start looking for a conversation. Launches the browser if it is not already open. The parameters are different according to the conversation type specified (text or video).

For text:

startConversation("text", topics?: string[], cookiesFilePath?: string)

For video:

startConversation(conversationType: "video", videoPath: string, topics?: string[], cookiesFilePath?: string)

Returns a promise that resolves once the page has been opened and all listeners have been initialized.

Example:

handler.startConversation("text", ["chat", "friends"], "./cookies");
handler.startConversation("video", "/Users/<user>/file.y4m", ["chat", "friends"], "./cookies");

sendMessage(message: string, delay?: number)

Sends message to the stranger. A delay between keystrokes can be given. This delay is so that the information "Stranger is typing..." is displayed for a given amount of time. The default delay is 50ms.

Returns a promise that resolves once the message has been sent.

Example:

handler.sendMessage("Hi there", 50);

solveCaptchaWith2CaptchaApiKey(captchaIdentifier: string, twoCaptchaAPIKey: string)

Included is a way to solve captchas using the 2captcha API. When a captcha is displayed on screen, the onCaptcha event is triggered, calling the bound function with a captcha identifier. This built-in method can be used as follows:

Returns a promise that resolves once the captcha has been solved.

handler.onCaptcha(captchaIdentifier => {
	handler.solveCaptchaWith2CaptchaApiKey(captchaIdentifier, "api_key");
});

solveCaptcha(captchaResult: string)

You can use the captcha identifier with any API to solve this captcha. Once a result is given by the API, you can solve the captcha as follows:

Returns a promise that resolves once the captcha has been solved.

handler.onCaptcha(captchaIdentifier => {
	const result = getResultFromYourAPI(captchaIdentifier).then(result => handler.solveCaptcha(result));
});

exit()

Closes the browser.

Returns a promise that resolves once the browser has been closed.

handler.exit();