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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chat-sdk-v2

v0.0.9

Published

A lightweight chat widget SDK using iframe

Readme

Chat SDK v2

A lightweight, iframe-based chat widget SDK built with vanilla JavaScript. This SDK allows you to easily integrate a chat widget into any website without dependencies on React or other frameworks.

Features

  • 🚀 Zero Dependencies: Pure JavaScript, no React or other framework dependencies
  • 📱 Responsive Design: Works seamlessly on desktop and mobile devices
  • 🎨 Customizable: Configurable colors, positions, sizes, and styles
  • 🔒 Secure: Uses iframe sandboxing for security
  • 📦 Lightweight: Minimal bundle size
  • 🎯 Shadow DOM: Prevents style conflicts with host website
  • 📡 Message Passing: Built-in communication with iframe content
  • 🎛️ Event System: Listen to widget events and iframe messages

Installation

NPM/Yarn

npm install chat-sdk-v2
# or
yarn add chat-sdk-v2

CDN

<script src="https://unpkg.com/chat-sdk-v2@latest/dist/chat-sdk-v2.umd.js"></script>

Quick Start

ES Modules

import { initChatSDK } from "chat-sdk-v2";

const chatWidget = initChatSDK({
  iframeUrl: "https://your-chat-app.com",
  position: "bottom-right",
  primaryColor: "#3B82F6",
});

UMD (Script Tag)

<script src="https://unpkg.com/chat-sdk-v2@latest/dist/chat-sdk-v2.umd.js"></script>
<script>
  const chatWidget = window.ChatSDK.init({
    iframeUrl: "https://your-chat-app.com",
    position: "bottom-right",
    primaryColor: "#3B82F6",
  });
</script>

CommonJS

const { initChatSDK } = require("chat-sdk-v2");

const chatWidget = initChatSDK({
  iframeUrl: "https://your-chat-app.com",
});

Configuration Options

const config = {
  iframeUrl: "https://your-chat-app.com", // Required: URL to load in iframe
  position: "bottom-right", // Position: 'bottom-right', 'bottom-left', 'top-right', 'top-left'
  primaryColor: "#3B82F6", // Primary color (chat button background)
  secondaryColor: "#10B981", // Secondary color (for custom styling)
  width: 400, // Widget width in pixels
  height: 600, // Widget height in pixels
  startOpen: false, // Whether to start with chat open
  customStyles: {
    // Custom CSS styles
    ".chat-widget-container": {
      "border-radius": "16px",
      "box-shadow": "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
    },
  },
};

const chatWidget = initChatSDK(config);

API Methods

// Open the chat widget
chatWidget.open();

// Close the chat widget
chatWidget.close();

// Toggle the chat widget
chatWidget.toggle();

// Check if chat is open
const isOpen = chatWidget.isOpen();

// Change iframe URL
chatWidget.setUrl("https://new-chat-url.com");

// Send message to iframe
chatWidget.postMessage({ type: "greeting", data: "Hello!" });

// Listen to messages from iframe
const unsubscribe = chatWidget.onMessage((message) => {
  console.log("Received from iframe:", message);
});

// Update configuration
chatWidget.updateConfig({
  primaryColor: "#FF6B6B",
  secondaryColor: "#4ECDC4",
});

// Get current configuration
const currentConfig = chatWidget.getConfig();

// Destroy the widget
chatWidget.destroy();

Event Handling

Listen to chat widget events:

// Chat opened event
window.addEventListener("chatSDKOpened", (event) => {
  console.log("Chat widget opened", event.detail);
});

// Chat closed event
window.addEventListener("chatSDKClosed", (event) => {
  console.log("Chat widget closed", event.detail);
});

// Iframe loaded event
window.addEventListener("chatSDKIframeLoaded", (event) => {
  console.log("Iframe loaded successfully", event.detail);
});

// Chat destroyed event
window.addEventListener("chatSDKDestroyed", (event) => {
  console.log("Chat widget destroyed", event.detail);
});

Message Communication

Sending Messages to Iframe

// Send structured data
chatWidget.postMessage({
  type: "user_info",
  data: {
    userId: "12345",
    name: "John Doe",
    email: "[email protected]",
  },
});

// Send simple message
chatWidget.postMessage("Hello from parent window!");

Receiving Messages from Iframe

const unsubscribe = chatWidget.onMessage((message) => {
  if (message.type === "chat_ready") {
    console.log("Chat is ready to receive messages");
  } else if (message.type === "new_message") {
    console.log("New chat message:", message.data);
  }
});

// Unsubscribe when no longer needed
unsubscribe();

Styling and Customization

Custom Colors

const chatWidget = initChatSDK({
  iframeUrl: "https://your-chat-app.com",
  primaryColor: "#FF6B6B", // Chat button color
  secondaryColor: "#4ECDC4", // Available for custom styling
});

Custom CSS Styles

const chatWidget = initChatSDK({
  iframeUrl: "https://your-chat-app.com",
  customStyles: {
    ".chat-widget-container": {
      "border-radius": "20px",
      "box-shadow": "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
      border: "2px solid #e2e8f0",
    },
    ".chat-toggle-button": {
      width: "70px",
      height: "70px",
    },
  },
});

Positioning

Choose from four predefined positions:

  • bottom-right (default)
  • bottom-left
  • top-right
  • top-left

Development

Setup

# Clone the repository
git clone <repository-url>
cd chat-sdk-v2

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

Demo

Run npm run dev and visit http://localhost:5173 to see the interactive demo.

Browser Support

  • Chrome/Edge 88+
  • Firefox 78+
  • Safari 14+
  • Modern mobile browsers

Security

The iframe is sandboxed with the following permissions:

  • allow-same-origin: Allows iframe to access same origin
  • allow-scripts: Allows JavaScript execution
  • allow-forms: Allows form submission
  • allow-popups: Allows popups (for OAuth, etc.)
  • allow-popups-to-escape-sandbox: Allows popups to escape sandbox

License

MIT License - see LICENSE file for details.