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

cross-iframe-rpc

v1.2.1

Published

A tool to help you develop a Chrome Extension page using your web dev server!

Readme

cross-iframe-rpc

Build a bridge between the iframe and the main window; it allows the iframe to cross-origin invoke functions in the main window. Similar to the RPC, but it added callback support.

What can it do?

The main purpose of this project is to develop a Chrome Extension. After everything setup, you can invoke chrome API in your iframe directly!


Generally, we have two ways to develop/organize our code in a Chrome Extension:

  • Without any build tool, write everything yourself.
  • Using rollup, webpack, etc., to build the code.

The first one is a good choice if your extension is light. But for some bigger extensions, it’s better to depend on build tools.

Because of the strict CSP limitations, We could only use build + watch to develop our extension. It is very slow and has bad performance.

**Why can't we start a web development server through Vite or other tools and let the extension page use our development server? **

After some research, I found that an iframe could do this. However, we can't access the Chrome API in our iframe, and that is what our library will do.

Theory

Listen for the message event in the main window and iframe, and use postMessage to invoke the API indirectly.

Quick Start

Demo Project

Install dependency:

npm install cross-iframe-rpc

1. Set The Dev Server Port Fixed.

You have to set your dev server port fixed. For example(Vite):

export default defineConfig({
  server: {
    port: 17000,
    strictPort: true
  },
})

2. Create Basic Template

Create a Html template, and import the page via an iframe(popup-dev.html):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body style="margin: 0">
<!-- src is your dev server's page -->
<iframe style="width: 500px;height: 500px;border:none;" id="iframe" src="http://localhost:17000/popup/popup.html"></iframe>
<!-- Additional script, check step 3  -->
<script type="module" src="popup.ts"></script>
</body>
</html>

popup.ts:

// popup.ts
import {setupInMainWindow} from "cross-iframe-rpc";

const iframe = document.getElementById('iframe') as HTMLIFrameElement
setupInMainWindow({
  iframe,
  delegateTarget: chrome,
})

3. Create Init Script In Dev Server

See main.tsx:

import { setupInIframe } from 'cross-iframe-rpc'

if (process.env.NODE_ENV === 'development') {
  window.chrome = setupInIframe<typeof chrome>()
}

This file should be your page entrance. We created a 'client' here; it will communicate with the outer window.

4. Use Chrome Api In Your Dev Server Code

See App.tsx

// no additional steps, use chrome directly.
const tabs = await chrome.tabs.query({ currentWindow: true, active: true })
alert('Your current tab url is:\n' + tabs[0].url)

Limitations

  • Only allow function invoke.
  • The type of return value always be Promise.

API

createBridgePeerClient

Create a peer client.


Parameters

target any

The object that you want to proxy. After you provide this, the corresponding client could invoke the API on this object.


poster MessagePoster

The events API.


maxFunctionCacheSize number Optional

Max function cache size, default is 50.

Because the lifecycle of the function is uncertain, we could only cache all the functions to avoid being recycled. When it reaches this size, the least recently unused function will be removed.

accessProperty

Access specific property.


Parameters

target object

Proxied target, see example below for more details.

Example

import { createBridePeerClientWithTypeOnly, accessProperty } from 'cross-iframe-rpc'
// remote
const remoteObject = {
    round: {
      apple: 'yummy!'
    }
}

// client
const obj = createBridePeerClientWithTypeOnly<typeof remoteObject>({
  // ...
})

accessProperty(await accessProperty(obj.round.apple)).then(r => {
  // yummy!
  console.log(r)
})