New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webext-messenger

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webext-messenger - npm Package Compare versions

Comparing version 0.9.3 to 0.10.0

37

distribution/index.js

@@ -17,10 +17,6 @@ import pRetry from "p-retry";

const handlers = new Map();
async function handleMessage(message, sender) {
const handler = handlers.get(message.type);
if (!handler) {
throw new Error("No handler registered for " + message.type);
}
async function handleCall(message, sender, call) {
console.debug(`Messenger:`, message.type, message.args, "from", { sender });
// The handler could actually be a synchronous function
const response = await Promise.resolve(handler.call(sender, ...message.args)).then((value) => ({ value }), (error) => ({
const response = await Promise.resolve(call).then((value) => ({ value }), (error) => ({
// Errors must be serialized because the stacktraces are currently lost on Chrome and

@@ -33,2 +29,13 @@ // https://github.com/mozilla/webextension-polyfill/issues/210

}
async function handleMessage(message, sender) {
if (message.target) {
const publicMethod = getContentScriptMethod(message.type);
return handleCall(message, sender, publicMethod(message.target, ...message.args));
}
const handler = handlers.get(message.type);
if (handler) {
return handleCall(message, sender, handler.apply(sender, message.args));
}
throw new Error("No handler registered for " + message.type);
}
// Do not turn this into an `async` function; Notifications must turn `void`

@@ -72,3 +79,3 @@ function manageConnection(type, options, sendMessage) {

}
function makeMessage(type, args) {
function makeMessage(type, args, target) {
return {

@@ -78,2 +85,3 @@ __webext_messenger__,

args,
target,
};

@@ -83,8 +91,11 @@ }

const publicMethod = (target, ...args) => {
const sendMessage = async () => {
var _a;
return browser.tabs.sendMessage(target.tabId, makeMessage(type, args),
// `frameId` must be specified. If missing, the message would be sent to every frame
{ frameId: (_a = target.frameId) !== null && _a !== void 0 ? _a : 0 });
};
// eslint-disable-next-line no-negated-condition -- Looks better
const sendMessage = !browser.tabs
? async () => browser.runtime.sendMessage(makeMessage(type, args, target))
: async () => {
var _a;
return browser.tabs.sendMessage(target.tabId, makeMessage(type, args),
// `frameId` must be specified. If missing, the message is sent to every frame
{ frameId: (_a = target.frameId) !== null && _a !== void 0 ? _a : 0 });
};
return manageConnection(type, options, sendMessage);

@@ -91,0 +102,0 @@ };

{
"name": "webext-messenger",
"version": "0.9.3",
"version": "0.10.0",
"description": "Browser Extension component messaging framework",

@@ -114,3 +114,4 @@ "keywords": [],

"startUrl": [
"https://legiblenews.com/"
"https://legiblenews.com/",
"https://rawtext.club/"
]

@@ -117,0 +118,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc