New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

webext-ipc

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webext-ipc

This is a simple library that will allow for communication between a web extensions background and client scripts. The communication is all typed, and allows for things like errors handling. There is a resolver like interface to handle messages in an enca

latest
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

Webext IPC

This is a simple library that will allow for communication between a web extensions background and client scripts. The communication is all typed, and allows for things like errors handling. There is a resolver like interface to handle messages in an encapsulated way.

Usage

Background

The background script can handle messages but also send them as well! The library is universal, so the same code can be used in both the background and client scripts. Here is a example of a background script handling some messages ( common ):

import { WebExtIPC } from 'webext-ipc'

interface SharedMessages {
  ping: {
    message: { type: 'ping' }
    response: { type: 'pingResponse'; pong: boolean }
  }
}

const ipc = WebExtIPC.from<SharedMessages>()

ipc.addMessageResolvers({
  ping: async (message) => {
    return { type: 'pingResponse', pong: true }
  },
})

Client

The client script can also handle messages, but also send them as well! Here is the client code sending some messages.

import { WebExtIPC } from 'webext-ipc'

const ipc = WebExtIPC.from<SharedMessages>()

ipc.sendMessage({ type: 'ping' }).then((response) => {
  console.log(response.pong)
})

FAQs

Package last updated on 03 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts