0.1.5 • Published 1 year ago

web-ext-msg-passing v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm version

web extension message passing wrapped

functional interface web extension message passing wrapped

Example

Refer to this repository for an example of how to use it

Installation

Using npm:

npm install --save web-ext-msg-passing

or using yarn:

yarn add web-ext-msg-passing

Usage

Basic Usage

background:

import { listen, listenGroup, installListener } from "web-ext-msg-passing"

// installListener is required if you want listen event
installListener()

// listen one event
listen("callApi", () => {
  return fetch("<YOUR API URI>").then(res => res.json())
})

// listen multiple event
listenGroup({
  callApi2(parameter) {
    return fetch("<YOUR API URI>", {
      body: JSON.stringify(parameter)
    }).then(res => res.json())
  },
  otherFn(parameter) {
    // do something...
  }
})

content script or popup:

import { send } from "web-ext-msg-passing"

// get api background response.
await send("callApi")
// get api background response with payload.
await send("callApi2", {id: 123})
// call background listener but not need response.
send("otherFn", {id: 3})

Send event to content script from background or popup

background or popup:

import { sendToContent } from "web-ext-msg-passing"

sendToContent("getContentHtml").then(response => {
  // response will get current page html
})

content script:

import { installListener, listen } from "web-ext-msg-passing"

// installListener is required if you want listen event
installListener()

// listen event
listen("getContentHtml", () => document.documentElement.innerHTML)

Typescript

Refer to this repository for an example of how use in typescript

0.1.2

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.5

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago