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

browserstack-client

v3.5.5

Published

BrowserStack APIs client library for node.js

Downloads

109

Readme

BrowserStack Client

This module interfaces all REST APIs offered by BrowserStack.

Build Status

Installation

$ npm i --save-dev browserstack-client

Requirements

Please ensure that your BrowserStack account contains the required subscription(s) for using the APIs provided by this module.

Add your BrowserStack username and API key to the following environment variables for your shell.

You may also supply these credentials in code when creating an instance of an API client. See options.username and options.key.

BROWSERSTACK_USERNAME=<your-username>
BROWSERSTACK_KEY=<your-access-key>

Basic features require Fetch API support in your JavaScript runtime (globalThis.fetch).

Additional features (running BrowserStackLocal binary) require node.js runtime.

Basic Usage

// index.mjs
import { BrowserStack } from "browserstack-client";

// set environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_KEY

// BrowserStack JavaScript Testing API
const jsTestingClient = new BrowserStack.JSTestingClient();
/* ...or
const jsTestingClient = new BrowserStack.JSTestingClient({
  username: "<browserstack-username>",
  key: "<browserstack-access-key>",
});
*/

console.log(await jsTestingClient.getAccountStatus());

// BrowserStack Automate API
const automateClient = new BrowserStack.AutomateClient();
console.log(await automateClient.getPlan());

// BrowserStack App Automate API
const appAutomateClient = new BrowserStack.AppAutomateClient();
console.log(await appAutomateClient.getPlan());

// BrowserStack Screenshots API
const screenshotsClient = new BrowserStack.ScreenshotsClient();
console.log(await screenshotsClient.getBrowsers());

// BrowserStack Local Testing API
const localTestingClient = new BrowserStack.LocalTestingClient();
console.log(await localTestingClient.getBinaryInstances());

Additional Features

Some features leverage node.js built-in modules (node:*) that may not be available in other JavaScript runtimes (such as Deno).

These are bundled separately along with all basic features from above.

// index.mjs
import { BrowserStack } from "browserstack-client/node";

const localTestingBinary = new BrowserStack.LocalTestingBinary({
  key: "<browserstack-access-key>", // or set environment variable BROWSERSTACK_KEY
  binHome: "<path-to-store-BrowserStackLocal-binary>", // or set environment variable BROWSERSTACK_LOCAL_BINARY_PATH
});

console.log(await localTestingBinary.start());
console.log(await localTestingBinary.stop());

Deno Sample

/**
 * @run --allow-read --allow-net --allow-env index.ts
 */

import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
import { BrowserStack } from "https://esm.sh/browserstack-client@latest";

const env = await load();

const options = {
  username: env.BROWSERSTACK_USERNAME,
  key: env.BROWSERSTACK_KEY,
};

// BrowserStack JavaScript Testing API
const jsTestingClient = new BrowserStack.JSTestingClient(options);
console.log(await jsTestingClient.getAccountStatus());

Documentation

Please refer to the documentation for methods available for each of these clients.

Proxy Support

npm install node-fetch
npm install proxy-agent // or proxy specific https-proxy-agent (see docs)
// index.mjs
import { JSTestingClient } from "browserstack-client";
import fetch from "node-fetch";
import { ProxyAgent } from "proxy-agent";

// Docs:
// https://www.npmjs.com/package/node-fetch#custom-agent
// https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent

const agent = new ProxyAgent();

// BrowserStack JavaScript Testing API
const jsTestingClient = new JSTestingClient({
  username: "<browserstack-username>",
  key: "<browserstack-access-key>",
  // provide your own Fetch API implementation
  fetch: (url, init) => fetch(url, { ...init, agent }),
});

console.log(await jsTestingClient.getAccountStatus());

Thanks

Sponsored access to BrowserStack, courtesy BrowserStack.