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

@kameleo/local-api-client

v3.4.0

Published

This JavaScript/TypeScript package provides convenient access to the Local API REST interface of the Kameleo Client.

Downloads

175

Readme

Kameleo Local API Client

With Kameleo, you can easily create multiple virtual browser profiles to work with multiple accounts. It helps you hide your actual timezone, geolocation, language, IP address and creates natural browser fingerprints to prevent detection by anti-bot systems. Kameleo is compatible with Selenium, Playwright, and Puppeteer frameworks for automating web scraping tasks. This JavaScript/TypeScript package provides convenient access to the Local API REST interface of the Kameleo Client. See the article in our knowledge base for Getting Started with Kameleo Automation.

Features

  • Stay completely undetected, so websites won't be able to detect that you are using automation tools
  • Start unlimited number of profiles with different natural browser fingerprints
  • Use authenticated HTTP/SOCKS/SSH proxies in browsers
  • Create isolated browsing environments simultaneously
  • Use real browser profiles of Chrome, Firefox, Safari and Edge
  • Edit, Import or Export browser cookies
  • Modify WebRTC parameters
  • Modify Geolocation settings
  • Modify Timezone and Language settings
  • Modify WebGL fingerprint
  • Modify 2D Canvas fingerprint
  • Modify Navigator properties
  • Modify Screen resolution

Note: You need Automation package of Kameleo to access the features described below.

Quickstart Guide

1. Install package

npm install @kameleo/local-api-client

2. Start the Kameleo.CLI on your computer

./Kameleo.CLI email="[email protected]" password="Pa$$w0rd"

3. Start a browser with out-of-the-box fingerprinting protection

import { KameleoLocalApiClient, BuilderForCreateProfile } from '@kameleo/local-api-client';

const client = new KameleoLocalApiClient();
const baseProfiles = await client.searchBaseProfiles({
    deviceType: 'desktop',
    browserProduct: 'chrome',
});

// Create a new profile with recommended settings
// for browser fingerprinting protection
const requestBody = BuilderForCreateProfile
    .forBaseProfile(baseProfiles[0].id)
    .setName('example profile')
    .setRecommendedDefaults()
    .build();
const profile = await client.createProfile({
    body: requestBody,
});

// Start the browser
await client.startProfile(profile.id);

// At this point you can automate the browser with your favorite framework

Automate Kameleo profiles with Selenium

Kameleo gives you the ability to control any supported browser using Selenium. It uses the WebDriver protocol, a W3C specification, and industry-standard to interact with a browser.

You need to import the official Selenium library.

import { Builder } from 'selenium-webdriver';
// Connect to the running browser instance using WebDriver
const kameleoPort = 5050;
const builder = new Builder()
    .usingServer(`http://localhost:${kameleoPort}/webdriver`)
    .withCapabilities({
        'kameleo:profileId': profile.id,
        browserName: 'Kameleo',
    });
const webdriver = await builder.build();

// Use any WebDriver command to drive the browser
// and enjoy full protection from bot detection products
await webdriver.get('https://google.com');

The full example can be found here.

Automate Kameleo profiles with Puppeteer (Chromium-based)

Kameleo lets you control Chromium-based browsers (sorry Firefox fans) using the official Puppeteer library. In this simple example you can see how to connect to the browser that Kameleo starts.

You need to import the official Puppeteer library.

import puppeteer from 'puppeteer';
// Connect to the browser through CDP
const kameleoPort = 5050;
const browserWSEndpoint = `ws://localhost:${kameleoPort}/puppeteer/${profile.id}`;
const browser = await puppeteer.connect({
    browserWSEndpoint, defaultViewport: null,
});
const page = await browser.newPage();

// Use any Puppeteer command to drive the browser
// and enjoy full protection from bot detection products
await page.goto('https://google.com');

The full example can be found here.

Automate Kameleo profiles with Playwright

Kameleo allows you to control the browser with the official Playwright library. It works little bit different with Chromium-based browsers and Firefox, so we provide an example for both. Here we showcase how you can connect to the browser that is already started by Kameleo.

You need to import the official Playwright library.

import playwright from 'playwright';

You can find more details here: Using Kameleo with Playwright framework – Kameleo Support Center.

Chromium-based profiles with Playwright

// Connect to the browser with Playwright through CDP
const kameleoPort = 5050;
const browserWSEndpoint = `ws://localhost:${kameleoPort}/playwright/${profile.id}`;
const browser = await playwright.chromium.connectOverCDP(browserWSEndpoint);
const context = browser.contexts()[0]; // It is recommended to work on the default context. New context will work in incognito mode without spoofing.
const page = await context.newPage();

// Use any Playwright command to drive the browser
// and enjoy full protection from bot detection products
await page.goto('https://google.com');

The full example can be found here.

Firefox-based profiles with Playwright

// Connect to the browser with Playwright
const kameleoPort = 5050;
const browserWSEndpoint = `ws://localhost:${kameleoPort}/playwright/${profile.id}`;

// The Playwright framework is not designed to connect to already running
// browsers. To overcome this limitation, a tool bundled with Kameleo, named
// pw-bridge will bridge the communication gap between the running Firefox
// instance and this playwright script.
// The exact path to the bridge executable is subject to change
let pwBridgePath = process.env.PW_BRIDGE_PATH;
if (!pwBridgePath && process.platform === 'win32') {
    pwBridgePath = `${process.env.LOCALAPPDATA}\\Programs\\Kameleo\\pw-bridge.exe`;
} else if (!pwBridgePath && process.platform === 'darwin') {
    pwBridgePath = '/Applications/Kameleo.app/Contents/MacOS/pw-bridge';
}

const browser = await playwright.firefox.launchPersistentContext('', {
    executablePath: pwBridgePath,
    args: [`-target ${browserWSEndpoint}`],
    persistent: true,
    viewport: null,
});

// Kameleo will open the a new page in the default browser context.
// NOTE: We DO NOT recommend using multiple browser contexts, as this might interfere
//       with Kameleo's browser fingerprint modification features.
const page = await browser.newPage();

// Use any Playwright command to drive the browser
// and enjoy full protection from bot detection products
await page.goto('https://google.com');

The full example can be found here.

Automate mobile profiles

Kameleo can emulate mobile devices in the custom built Chromium.

// Search for a mobile Base Profiles
const baseProfileList = await client.searchBaseProfiles({
	deviceType: 'mobile',
	osFamily: 'ios',
	browserProduct: 'safari',
	language: 'en-us',
});

// Create a new profile with recommended settings
// Choose one of the Base Profiles
// Set the launcher to 'chromium' so the mobile profile will be started in Chroma browser
const createProfileRequest = BuilderForCreateProfile
	.forBaseProfile(baseProfileList[0].id)
    .setName('automate mobile profiles on desktop example')
	.setRecommendedDefaults()
	.setLauncher('chromium')
	.build();
const profile = await client.createProfile({
    body: createProfileRequest,
});

// Start the profile
await client.startProfileWithOptions(profile.id, {
	body: {
		// This allows you to click on elements using the cursor when emulating a touch screen in the brower.
		// If you leave this out, your script may time out after clicks and fail.
		additionalOptions: [
			{
				key: 'disableTouchEmulation',
				value: true,
			},
		],
	},
});

// At this point you can automate the browser with your favorite framework

The full example can be found here.

Example codes

Several examples have been prepared in a different repository to showcase the most interesting features. Feel free to create a pull request to add new example codes.

  • Finding base profiles
  • Creating profiles with custom options
  • Updating profiles with new settings
  • How to start a profile
  • Using Selenium with Local API
  • Using Playwright with Kameleo
  • Using Puppeteer with Kameleo
  • How to emulate mobile devices
  • Adding an HTTP, SOCKS or SSH proxy to profile
  • Saving/Loading a browsing session to/from a .kameleo file
  • Modify and Delete browser cookies
  • Start profile with extra WebDriver capabilities
  • How to duplicate virtual browser profiles
  • Refresh the browser of the emulated profiles

Note: If you are interested in more information about Kameleo, or have encountered an issue with using it, please check out our Help Center.

Endpoints

Available API endpoints with exhaustive descriptions and example values are documented on this SwaggerHub page. This package has built-in IntelliSense support in Visual Studio Code, no extra package installation needed.

Package

This package can be found on npm here: @kameleo/local-api-client.

License

This project is released under MIT License. Please refer the LICENSE.txt for more details.