
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
A tiny, flexible, fast, promise-based library for messaging in Firefox and Chrome extensions.
npm install --save msgx
Try this example yourself with cd test_extension && npm run build
import client from 'msgx/client'
const actions = { zoom: (zoom) => console.log(`zoom ${zoom}`) }
function onDisconnect () { console.log('disconnected') }
const debug = true
const msg = client(actions, onDisconnect, debug)
msg('zoom').then(zoom => console.log(`init zoom ${zoom})`))
msg('sum', 7).then(sum => console.log(`new sum ${sum}`)) // 7
msg('sum', 3).then(sum => console.log(`new sum ${sum}`)) // 10
import server from 'msgx/server'
import browser from 'webextension-polyfill'
const actions = {
sum: (n, _, data) => data.sum += n,
zoom: (_, sender) => browser.tabs.getZoom(sender.tab.id)
}
function onConnect (sender, msg, data) {
function onZoomChange ({ tabId, newZoomFactor }) {
if (sender.tab.id === tabId) msg('zoom', newZoomFactor)
}
browser.tabs.onZoomChange.addListener(onZoomChange)
data.onZoomChange = onZoomChange
data.sum = 0
}
function onDisconnect (sender, data) {
console.log(`final sum ${data.sum}`)
browser.tabs.onZoomChange.removeListener(data.onZoomChange)
}
const debug = true
server(actions, onConnect, onDisconnect, debug)
(actions, onConnect, onDisconnect, debug) => void
(arg, sender, data) => result
(sender, msg, data) => void
(action, arg) => void
(sender, data) => void
(actions, onDisconnect, debug) => msg
(arg) => any
(sender) => void
(action, arg) => Promise<result>
msgx is tiny! Read its source code below.
export default function (actions = {}, onDisconnect, debug = true) {
const port = chrome.runtime.connect()
let t = 0
const transactions = {}
port.onMessage.addListener(([t, actionOrResult, arg]) => {
if (t > 0) {
if (debug) console.log(`rx:${t}`, actionOrResult)
transactions[t](actionOrResult)
} else {
if (debug) console.log(`rx:${t}:${actionOrResult}`, arg)
actions[actionOrResult](arg)
}
})
onDisconnect && port.onDisconnect.addListener(onDisconnect)
return (action, arg) => new Promise(resolve => {
t++
if (debug) console.log(`tx:${t}:${action}`, arg)
port.postMessage([t, action, arg])
transactions[t] = resolve
})
}
export default function (actions = {}, onConnect, onDisconnect, debug = true) {
chrome.runtime.onConnect.addListener(port => {
if (debug) console.log('connect', port.sender)
const data = {}
port.onMessage.addListener(async ([t, action, arg]) => {
if (debug) console.log(`rx:${t}:${action}`, arg)
const reply = await actions[action](arg, port.sender, data)
port.postMessage([ t, reply ])
if (debug) console.log(`tx:${t}`, reply)
})
const msg = (action, arg) => {
if (debug) console.log(`tx:${0}:${action}`, arg)
port.postMessage([0, action, arg])
}
onConnect && onConnect(port.sender, msg, data)
onDisconnect && port.onDisconnect.addListener(() => onDisconnect(port.sender, data))
})
}
FAQs
tiny, flexible, fast, promise-based, webextension messaging
The npm package msgx receives a total of 57 weekly downloads. As such, msgx popularity was classified as not popular.
We found that msgx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.