2.2.0 • Published 6 months ago

@webext-core/messaging v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@webext-core/messaging

A light-weight, type-safe wrapper around the browser.runtime messaging APIs. Supports all browsers (Chrome, Firefox, Safari).

// ./messaging.ts
import { defineExtensionMessaging } from '@webext-core/messaging';

interface ProtocolMap {
  getStringLength(s: string): number;
}

export const { sendMessage, onMessage } = defineExtensionMessaging<ProtocolMap>();
// ./background.ts
import { onMessage } from './messaging';

onMessage('getStringLength', message => {
  return message.data.length;
});
// ./content-script.js or anywhere else
import { sendMessage } from './messaging';

const length = await sendMessage('getStringLength', 'hello world');

console.log(length); // 11

Get Started

See documentation to get started!

2.2.0

6 months ago

2.1.0

8 months ago

2.0.2

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago