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

@plasmohq/messaging

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plasmohq/messaging - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

2

dist/hook.js

@@ -1,1 +0,1 @@

import{useEffect as d,useRef as l,useState as x}from"react";import{nanoid as B}from"nanoid";var y=globalThis.browser?.runtime||globalThis.chrome?.runtime,w=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{if(!y)throw new Error("Extension runtime is not available");return y};var p=(e,t)=>!t.__internal&&e.source===globalThis.window&&e.data.name===t.name&&(t.relayId===void 0||e.data.relayId===t.relayId);var g=(e,t,s=globalThis.window)=>{let o=async a=>{if(p(a,e)&&!a.data.relayed){let n={name:e.name,relayId:e.relayId,body:a.data.body},i=await t?.(n);s.postMessage({name:e.name,relayId:e.relayId,instanceId:a.data.instanceId,body:i,relayed:!0},{targetOrigin:e.targetOrigin||"/"})}};return s.addEventListener("message",o),()=>s.removeEventListener("message",o)};var b=async e=>r().sendMessage(e.extensionId??null,e);var u=e=>g(e,b);var M=e=>{let t=async(o,a,n)=>{await e?.({...o,sender:a},{send:i=>n(i)})},s=(o,a,n)=>{t(o,a,n)};return r().onMessage.addListener(s),()=>{r().onMessage.removeListener(s)}};var c=new Map,f=e=>{let t=c.get(e);if(t)return t;let s=r().connect({name:e});return c.set(e,s),s},P=e=>{c.delete(e)},m=(e,t,s)=>{let o=f(e);function a(){P(e),s?.()}return o.onMessage.addListener(t),o.onDisconnect.addListener(a),{port:o,disconnect:()=>{o.onMessage.removeListener(t),o.onDisconnect.removeListener(a)}}};var G=e=>{let[t,s]=x();return d(()=>M(async(o,a)=>{s(o.body),await e(o,a)}),[e]),{data:t}},J=e=>{let t=l(),s=l(0),[o,a]=x();return d(()=>{if(!e)return null;let{port:n,disconnect:i}=m(e,R=>{a(R)},()=>{s.current=s.current+1});return t.current=n,i},[e,s.current]),{data:o,send:n=>{t.current.postMessage({name:e,body:n})},listen:n=>m(e,n)}};function K(e){d(()=>u(e),[])}var Q=(e,t)=>{let s=l();return d(()=>(s.current=g(e,t),s.current),[]),()=>s.current?.()};export{G as useMessage,K as useMessageRelay,J as usePort,Q as useRelay};
import{useEffect as g,useRef as l,useState as x}from"react";import{nanoid as T}from"nanoid";var y=globalThis.browser?.runtime||globalThis.chrome?.runtime,w=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{if(!y)throw new Error("Extension runtime is not available");return y};var p=(e,s)=>!s.__internal&&e.source===globalThis.window&&e.data.name===s.name&&(s.relayId===void 0||e.data.relayId===s.relayId);var d=(e,s,t=globalThis.window)=>{let o=async n=>{if(p(n,e)&&!n.data.relayed){let a={name:e.name,relayId:e.relayId,body:n.data.body},i=await s?.(a);t.postMessage({name:e.name,relayId:e.relayId,instanceId:n.data.instanceId,body:i,relayed:!0},{targetOrigin:e.targetOrigin||"/"})}};return t.addEventListener("message",o),()=>t.removeEventListener("message",o)};var b=async e=>r().sendMessage(e.extensionId??null,e);var u=e=>d(e,b);var M=e=>{let s=async(o,n,a)=>{await e?.({...o,sender:n},{send:i=>a(i)})},t=(o,n,a)=>(s(o,n,a),!0);return r().onMessage.addListener(t),()=>{r().onMessage.removeListener(t)}};var m=new Map,f=e=>{let s=m.get(e);if(s)return s;let t=r().connect({name:e});return m.set(e,t),t},P=e=>{m.delete(e)},c=(e,s,t)=>{let o=f(e);function n(){P(e),t?.()}return o.onMessage.addListener(s),o.onDisconnect.addListener(n),{port:o,disconnect:()=>{o.onMessage.removeListener(s),o.onDisconnect.removeListener(n)}}};var G=e=>{let[s,t]=x();return g(()=>M(async(o,n)=>{t(o.body),await e(o,n)}),[e]),{data:s}},J=e=>{let s=l(),t=l(0),[o,n]=x();return g(()=>{if(!e)return null;let{port:a,disconnect:i}=c(e,R=>{n(R)},()=>{t.current=t.current+1});return s.current=a,i},[e,t.current]),{data:o,send:a=>{s.current.postMessage({name:e,body:a})},listen:a=>c(e,a)}};function K(e){g(()=>u(e),[])}var Q=(e,s)=>{let t=l();return g(()=>(t.current=d(e,s),t.current),[]),()=>t.current?.()};export{G as useMessage,K as useMessageRelay,J as usePort,Q as useRelay};

@@ -5,9 +5,9 @@ import { P as PlasmoMessaging, M as MessageName } from './types-a2e5594b.js';

/**
* Should only be called from CS or Ext Pages
* Extension Id is required to send a message from a CS in the main world
* TODO: Add a framework runtime check, using a global variable
* Send to Background Service Workers from Content Scripts or Extension pages.
* `extensionId` is required to send a message from a Content Script in the main world
*/
declare const sendToBackground: PlasmoMessaging.SendFx<MessageName>;
/**
* Send to CS from Ext pages or BGSW, default to active tab if no tabId is provided in the request
* Send to Content Scripts from Extension pages or Background Service Workers.
* Default to active tab if no tabId is provided in the request
*/

@@ -14,0 +14,0 @@ declare const sendToContentScript: PlasmoMessaging.SendFx;

@@ -1,1 +0,1 @@

import{nanoid as y}from"nanoid";var o=globalThis.browser?.runtime||globalThis.chrome?.runtime,d=globalThis.browser?.tabs||globalThis.chrome?.tabs,e=()=>{if(!o)throw new Error("Extension runtime is not available");return o};var I=r=>{let i=async(a,s,t)=>{await r?.({...a,sender:s},{send:g=>t(g)})},n=(a,s,t)=>{i(a,s,t)};return e().onMessage.addListener(n),()=>{e().onMessage.removeListener(n)}};export{I as listen};
import{nanoid as c}from"nanoid";var o=globalThis.browser?.runtime||globalThis.chrome?.runtime,d=globalThis.browser?.tabs||globalThis.chrome?.tabs,e=()=>{if(!o)throw new Error("Extension runtime is not available");return o};var E=r=>{let i=async(s,a,t)=>{await r?.({...s,sender:a},{send:g=>t(g)})},n=(s,a,t)=>(i(s,a,t),!0);return e().onMessage.addListener(n),()=>{e().onMessage.removeListener(n)}};export{E as listen};
{
"name": "@plasmohq/messaging",
"version": "0.6.0",
"version": "0.6.1",
"description": "Type-safe, zero-config messaging library for modern browser extensions",

@@ -114,14 +114,14 @@ "type": "module",

"devDependencies": {
"@jest/globals": "29.6.4",
"@jest/globals": "29.7.0",
"@jest/types": "29.6.3",
"@testing-library/react": "14.0.0",
"@types/chrome": "0.0.245",
"@types/node": "20.5.9",
"@types/react": "18.2.21",
"@testing-library/react": "14.1.0",
"@types/chrome": "0.0.251",
"@types/node": "20.9.0",
"@types/react": "18.2.37",
"cross-env": "7.0.3",
"jest": "29.6.4",
"jest-environment-jsdom": "29.6.4",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"rimraf": "5.0.1",
"rimraf": "5.0.5",
"ts-jest": "29.1.1",

@@ -132,3 +132,3 @@ "tsup": "7.2.0",

"dependencies": {
"nanoid": "4.0.2"
"nanoid": "5.0.3"
},

@@ -135,0 +135,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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