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

copilot-communication-service

v1.0.5

Published

A communication service for handling messages between parent window and Copilot

Readme

Copilot Communication Service

A communication service for handling messages between parent window and Copilot (iframe), with full TypeScript support.

Installation

npm install copilot-communication-service
# or
yarn add copilot-communication-service

Usage

Parent Window (Vanilla JS/TS)

import { CopilotService } from 'copilot-communication-service';

const iframe = document.getElementById('childFrame') as HTMLIFrameElement;
const parentBridge = new CopilotService(iframe.contentWindow!, '*');

// Listen for messages from child
parentBridge.subscribe('child-to-parent', (data) => {
  console.log('Received from child:', data.message);
});

// Send message to child
parentBridge.emit('parent-to-child', { message: 'Hello from parent!' });

Child Window (iframe)

import { CopilotService } from 'copilot-communication-service';

const childBridge = new CopilotService(window.parent, '*');

// Listen for messages from parent
childBridge.subscribe('parent-to-child', (data) => {
  console.log('Received from parent:', data.message);
});

// Send message to parent
childBridge.emit('child-to-parent', { message: 'Hello from child!' });

React/Vite Playground Example

你可以在 playground/ 目錄下找到完整的 React + Vite 父子頁面訊息互傳範例。

  • playground/parent.html:父頁面,載入 React 父元件與 iframe
  • playground/child.html:子頁面,載入 React 子元件
  • playground/ParentApp.tsxChildApp.tsx:React component 實作

啟動方式:

yarn dev
# or
npm run dev

然後瀏覽 http://localhost:5173/playground/parent.html


API

CopilotService

建構子

new CopilotService(targetWindow: Window, targetOrigin?: string)
  • targetWindow:要傳遞訊息的目標 window(父層用 iframe.contentWindow,子層用 window.parent)
  • targetOrigin:目標 origin,預設為 '*'

方法

  • emit(eventName: string, data: any): void
    發送事件到對方 window。
  • subscribe(eventName: string, handler: (data: any) => void): () => void
    訂閱事件,回傳取消訂閱函式。
  • post<T>(action: string, payload: any): Promise<T>
    發送請求並等待回應(進階用法)。

Unsubscribe 標準用法(React 範例):

useEffect(() => {
  const unsubscribe = bridgeRef.current.subscribe('eventName', handler);
  return () => {
    unsubscribe(); // component unmount 時自動解除訂閱
  };
}, []);

型別支援

  • 本套件自帶 TypeScript 型別,無需額外安裝 @types。

Enum

  • CopilotActionCopilotEvent 內建常用事件/行為名稱。

Build & Publish

  1. 打包(產生 JS 與型別):
    yarn build
    # or
    npm run build
  2. 發佈到 npm:
    npm publish --access public

Versioning (自動更新版號)

你可以用以下指令自動 bump 版本號:

# 升級 patch 版號(1.0.0 → 1.0.1)
yarn bump:patch

# 升級 minor 版號(1.0.0 → 1.1.0)
yarn bump:minor

# 升級 major 版號(1.0.0 → 2.0.0)
yarn bump:major

你也可以用以下指令自動產生 changelog、升級版本並自動發佈到 npm:

yarn release:patch   # 產生 patch 版本並自動發佈

yarn release:minor   # 產生 minor 版本並自動發佈

yarn release:major   # 產生 major 版本並自動發佈

每次發佈前請記得先升級版本號!


License

MIT