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

@aspectly/core

v0.1.0

Published

Core bridge framework for cross-platform communication between WebViews, iframes, and web applications

Downloads

282

Readme

@aspectly/core

The core bridge framework for cross-platform communication between WebViews, iframes, and web applications.

Installation

# npm
npm install @aspectly/core

# pnpm
pnpm add @aspectly/core

# yarn
yarn add @aspectly/core

Overview

@aspectly/core provides the foundational bridge communication layer that enables bidirectional message passing between different execution contexts:

  • WebView ↔ React Native: Communication between web content and React Native apps
  • iframe ↔ Parent Window: Communication between iframes and their parent pages
  • Browser Context: Standalone browser usage with global bridge instance

Quick Start

Inside a WebView or iframe

import { AspectlyBridge } from '@aspectly/core';

// Create a bridge instance
const bridge = new AspectlyBridge();

// Initialize with handlers for incoming requests
await bridge.init({
  greet: async (params: { name: string }) => {
    return { message: `Hello, ${params.name}!` };
  },
  getData: async () => {
    return { timestamp: Date.now() };
  },
});

// Send requests to the parent container
const result = await bridge.send('parentMethod', { data: 'value' });
console.log(result);

Browser Script Tag Usage

<script src="https://unpkg.com/@aspectly/core/dist/browser.js"></script>
<script>
  window.aspectlyBridge.init({
    greet: async (params) => ({ message: `Hello, ${params.name}!` })
  }).then(() => {
    console.log('Bridge initialized');
  });
</script>

API Reference

AspectlyBridge

The main class for bridge communication.

Constructor

const bridge = new AspectlyBridge(options?: BridgeOptions);

Options:

  • timeout?: number - Handler execution timeout in ms (default: 100000)

Methods

init(handlers?: BridgeHandlers): Promise<boolean>

Initialize the bridge with handlers for incoming requests.

await bridge.init({
  methodName: async (params) => {
    // Handle request and return result
    return { success: true };
  },
});
send<T>(method: string, params?: object): Promise<T>

Send a request to the other side.

const result = await bridge.send<{ data: string }>('getData', { id: 123 });
supports(method: string): boolean

Check if a method is supported by the other side.

if (bridge.supports('getData')) {
  const data = await bridge.send('getData');
}
isAvailable(): boolean

Check if the bridge is initialized and ready.

if (bridge.isAvailable()) {
  // Bridge is ready
}
subscribe(listener: BridgeListener): number

Subscribe to all result events for monitoring/debugging.

bridge.subscribe((result) => {
  console.log('Event:', result.method, result.data);
});
unsubscribe(listener: BridgeListener): void

Remove a result event listener.

destroy(): void

Cleanup bridge subscriptions.

bridge.destroy();

Error Handling

The bridge provides typed errors for different failure scenarios:

import { BridgeErrorType } from '@aspectly/core';

try {
  await bridge.send('unknownMethod');
} catch (error) {
  switch (error.error_type) {
    case BridgeErrorType.UNSUPPORTED_METHOD:
      console.log('Method not registered');
      break;
    case BridgeErrorType.METHOD_EXECUTION_TIMEOUT:
      console.log('Handler timed out');
      break;
    case BridgeErrorType.REJECTED:
      console.log('Handler threw error:', error.error_message);
      break;
    case BridgeErrorType.BRIDGE_NOT_AVAILABLE:
      console.log('Bridge not initialized');
      break;
  }
}

Architecture

The package consists of four layers:

  1. BridgeCore - Low-level platform detection and message serialization
  2. BridgeInternal - Protocol management and request/response lifecycle
  3. BridgeBase - Clean public API interface
  4. AspectlyBridge - Main entry point composing all layers

Related Packages

License

MIT