@plasmohq/messaging
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -1,1 +0,1 @@ | ||
var r=globalThis.browser?.runtime||globalThis.chrome?.runtime,s=globalThis.browser?.tabs||globalThis.chrome?.tabs,o=()=>{if(!r)throw new Error("Extension runtime is not available");return r};var n=()=>globalThis.__plasmoInternalPortMap,c=t=>{let e=n().get(t);if(!e)throw new Error(`Port ${t} not found`);return e};o().onMessage.addListener((t,a,e)=>{switch(t.__PLASMO_INTERNAL_SIGNAL__){case"__PLASMO_MESSAGING_PING__":{e(!0);break}}return!0});export{c as getPort,n as getPortMap}; | ||
var n=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{let t=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!t)throw new Error("Extension runtime is not available");return t};var a=()=>globalThis.__plasmoInternalPortMap,m=t=>{let e=a().get(t);if(!e)throw new Error(`Port ${t} not found`);return e};r().onMessage.addListener((t,o,e)=>{switch(t.__PLASMO_INTERNAL_SIGNAL__){case"__PLASMO_MESSAGING_PING__":{e(!0);break}}return!0});export{m as getPort,a as getPortMap}; |
@@ -1,1 +0,1 @@ | ||
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}; | ||
import{useEffect as g,useRef as l,useState as M}from"react";import{nanoid as E}from"nanoid";var P=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{let e=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!e)throw new Error("Extension runtime is not available");return e};var y=(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(y(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 R=async e=>r().sendMessage(e.extensionId??null,e);var p=e=>d(e,R);var u=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,b=e=>{let s=m.get(e);if(s)return s;let t=r().connect({name:e});return m.set(e,t),t},f=e=>{m.delete(e)},c=(e,s,t)=>{let o=b(e);function n(){f(e),t?.()}return o.onMessage.addListener(s),o.onDisconnect.addListener(n),{port:o,disconnect:()=>{o.onMessage.removeListener(s),o.onDisconnect.removeListener(n)}}};var z=e=>{let[s,t]=M();return g(()=>u(async(o,n)=>{t(o.body),await e(o,n)}),[e]),{data:s}},G=e=>{let s=l(),t=l(0),[o,n]=M();return g(()=>{if(!e)return null;let{port:a,disconnect:i}=c(e,x=>{n(x)},()=>{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 J(e){g(()=>p(e),[])}var K=(e,s)=>{let t=l();return g(()=>(t.current=d(e,s),t.current),[]),()=>t.current?.()};export{z as useMessage,J as useMessageRelay,G as usePort,K as useRelay}; |
@@ -1,1 +0,1 @@ | ||
import{nanoid as p}from"nanoid";var l=globalThis.browser?.runtime||globalThis.chrome?.runtime,d=globalThis.browser?.tabs||globalThis.chrome?.tabs,m=()=>{if(!l)throw new Error("Extension runtime is not available");return l},i=()=>{if(!d)throw new Error("Extension tabs API is not available");return d},c=async()=>{let e=i(),[a]=await e.query({active:!0,currentWindow:!0});return a},g=(e,a)=>!a.__internal&&e.source===globalThis.window&&e.data.name===a.name&&(a.relayId===void 0||e.data.relayId===a.relayId);var y=(e,a,n=globalThis.window)=>{let r=async s=>{if(g(s,e)&&!s.data.relayed){let o={name:e.name,relayId:e.relayId,body:s.data.body},t=await a?.(o);n.postMessage({name:e.name,relayId:e.relayId,instanceId:s.data.instanceId,body:t,relayed:!0},{targetOrigin:e.targetOrigin||"/"})}};return n.addEventListener("message",r),()=>n.removeEventListener("message",r)},b=(e,a=globalThis.window)=>new Promise((n,r)=>{let s=p(),o=new AbortController;a.addEventListener("message",t=>{g(t,e)&&t.data.relayed&&t.data.instanceId===s&&(n(t.data.body),o.abort())},{signal:o.signal}),a.postMessage({...e,instanceId:s},{targetOrigin:e.targetOrigin||"/"})});var x=async e=>m().sendMessage(e.extensionId??null,e),M=async e=>{let a=typeof e.tabId=="number"?e.tabId:(await c())?.id;if(!a)throw new Error("No active tab found to send message to.");return i().sendMessage(a,e)},E=M,u=e=>y(e,x),S=u,w=b,O=w;export{S as relay,u as relayMessage,E as sendToActiveContentScript,x as sendToBackground,w as sendToBackgroundViaRelay,M as sendToContentScript,O as sendViaRelay}; | ||
import{nanoid as b}from"nanoid";var l=globalThis.browser?.tabs||globalThis.chrome?.tabs,d=()=>{let e=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!e)throw new Error("Extension runtime is not available");return e},i=()=>{if(!l)throw new Error("Extension tabs API is not available");return l},m=async()=>{let e=i(),[a]=await e.query({active:!0,currentWindow:!0});return a},g=(e,a)=>!a.__internal&&e.source===globalThis.window&&e.data.name===a.name&&(a.relayId===void 0||e.data.relayId===a.relayId);var c=(e,a,n=globalThis.window)=>{let r=async s=>{if(g(s,e)&&!s.data.relayed){let o={name:e.name,relayId:e.relayId,body:s.data.body},t=await a?.(o);n.postMessage({name:e.name,relayId:e.relayId,instanceId:s.data.instanceId,body:t,relayed:!0},{targetOrigin:e.targetOrigin||"/"})}};return n.addEventListener("message",r),()=>n.removeEventListener("message",r)},y=(e,a=globalThis.window)=>new Promise((n,r)=>{let s=b(),o=new AbortController;a.addEventListener("message",t=>{g(t,e)&&t.data.relayed&&t.data.instanceId===s&&(n(t.data.body),o.abort())},{signal:o.signal}),a.postMessage({...e,instanceId:s},{targetOrigin:e.targetOrigin||"/"})});var p=async e=>d().sendMessage(e.extensionId??null,e),x=async e=>{let a=typeof e.tabId=="number"?e.tabId:(await m())?.id;if(!a)throw new Error("No active tab found to send message to.");return i().sendMessage(a,e)},h=x,M=e=>c(e,p),E=M,u=y,S=u;export{E as relay,M as relayMessage,h as sendToActiveContentScript,p as sendToBackground,u as sendToBackgroundViaRelay,x as sendToContentScript,S as sendViaRelay}; |
@@ -1,1 +0,1 @@ | ||
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}; | ||
import{nanoid as y}from"nanoid";var g=globalThis.browser?.tabs||globalThis.chrome?.tabs,s=()=>{let e=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!e)throw new Error("Extension runtime is not available");return e};var h=e=>{let r=async(a,t,n)=>{await e?.({...a,sender:t},{send:i=>n(i)})},o=(a,t,n)=>(r(a,t,n),!0);return s().onMessage.addListener(o),()=>{s().onMessage.removeListener(o)}};export{h as listen}; |
@@ -1,1 +0,1 @@ | ||
var a=globalThis.browser?.runtime||globalThis.chrome?.runtime,d=globalThis.browser?.tabs||globalThis.chrome?.tabs,i=()=>{if(!a)throw new Error("Extension runtime is not available");return a};var r=new Map,c=e=>{let t=r.get(e);if(t)return t;let n=i().connect({name:e});return r.set(e,n),n},m=e=>{r.delete(e)},p=(e,t,n)=>{let o=c(e);function s(){m(e),n?.()}return o.onMessage.addListener(t),o.onDisconnect.addListener(s),{port:o,disconnect:()=>{o.onMessage.removeListener(t),o.onDisconnect.removeListener(s)}}};export{c as getPort,p as listen,m as removePort}; | ||
var m=globalThis.browser?.tabs||globalThis.chrome?.tabs,a=()=>{let e=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!e)throw new Error("Extension runtime is not available");return e};var r=new Map,i=e=>{let t=r.get(e);if(t)return t;let n=a().connect({name:e});return r.set(e,n),n},c=e=>{r.delete(e)},l=(e,t,n)=>{let o=i(e);function s(){c(e),n?.()}return o.onMessage.addListener(t),o.onDisconnect.addListener(s),{port:o,disconnect:()=>{o.onMessage.removeListener(t),o.onDisconnect.removeListener(s)}}};export{i as getPort,l as listen,c as removePort}; |
@@ -1,1 +0,1 @@ | ||
var s=globalThis.browser?.runtime||globalThis.chrome?.runtime,b=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{if(!s)throw new Error("Extension runtime is not available");return s};var i=()=>globalThis.__plasmoInternalHubMap,m=()=>{let t=r();if(!t.onConnectExternal)throw new Error("onConnect External not available. You need externally_connectable entry possibly");globalThis.__plasmoInternalHubMap=new Map;let e=i();t.onConnectExternal.addListener(n=>{let o=n.sender.tab.id;e.has(o)||(e.set(o,n),n.onMessage.addListener(a=>{c({from:o,payload:a})}),n.onDisconnect.addListener(()=>{e.delete(o)}))})},c=t=>{i().forEach((n,o)=>{o!==t.from&&n.postMessage({...t,to:o})})},d=t=>{let e=r();if(!e.connect)throw new Error("runtime.connect not available. You need to use startHub in BGSW");return e.connect(t)};export{c as broadcast,d as connectToHub,i as getHubMap,m as startHub}; | ||
var c=globalThis.browser?.tabs||globalThis.chrome?.tabs,r=()=>{let t=globalThis.browser?.runtime||globalThis.chrome?.runtime;if(!t)throw new Error("Extension runtime is not available");return t};var s=()=>globalThis.__plasmoInternalHubMap,u=()=>{let t=r();if(!t.onConnectExternal)throw new Error("onConnect External not available. You need externally_connectable entry possibly");globalThis.__plasmoInternalHubMap=new Map;let e=s();t.onConnectExternal.addListener(n=>{let o=n.sender.tab.id;e.has(o)||(e.set(o,n),n.onMessage.addListener(a=>{i({from:o,payload:a})}),n.onDisconnect.addListener(()=>{e.delete(o)}))})},i=t=>{s().forEach((n,o)=>{o!==t.from&&n.postMessage({...t,to:o})})},m=t=>{let e=r();if(!e.connect)throw new Error("runtime.connect not available. You need to use startHub in BGSW");return e.connect(t)};export{i as broadcast,m as connectToHub,s as getHubMap,u as startHub}; |
@@ -1,1 +0,1 @@ | ||
import{nanoid as l}from"nanoid";var g=globalThis.browser?.runtime||globalThis.chrome?.runtime,d=globalThis.browser?.tabs||globalThis.chrome?.tabs;var i=(a,e)=>!e.__internal&&a.source===globalThis.window&&a.data.name===e.name&&(e.relayId===void 0||a.data.relayId===e.relayId);var b=(a,e,n=globalThis.window)=>{let r=async s=>{if(i(s,a)&&!s.data.relayed){let o={name:a.name,relayId:a.relayId,body:s.data.body},t=await e?.(o);n.postMessage({name:a.name,relayId:a.relayId,instanceId:s.data.instanceId,body:t,relayed:!0},{targetOrigin:a.targetOrigin||"/"})}};return n.addEventListener("message",r),()=>n.removeEventListener("message",r)},u=(a,e=globalThis.window)=>new Promise((n,r)=>{let s=l(),o=new AbortController;e.addEventListener("message",t=>{i(t,a)&&t.data.relayed&&t.data.instanceId===s&&(n(t.data.body),o.abort())},{signal:o.signal}),e.postMessage({...a,instanceId:s},{targetOrigin:a.targetOrigin||"/"})});export{b as relay,u as sendViaRelay}; | ||
import{nanoid as l}from"nanoid";var g=globalThis.browser?.tabs||globalThis.chrome?.tabs;var i=(a,e)=>!e.__internal&&a.source===globalThis.window&&a.data.name===e.name&&(e.relayId===void 0||a.data.relayId===e.relayId);var y=(a,e,n=globalThis.window)=>{let r=async s=>{if(i(s,a)&&!s.data.relayed){let o={name:a.name,relayId:a.relayId,body:s.data.body},t=await e?.(o);n.postMessage({name:a.name,relayId:a.relayId,instanceId:s.data.instanceId,body:t,relayed:!0},{targetOrigin:a.targetOrigin||"/"})}};return n.addEventListener("message",r),()=>n.removeEventListener("message",r)},b=(a,e=globalThis.window)=>new Promise((n,r)=>{let s=l(),o=new AbortController;e.addEventListener("message",t=>{i(t,a)&&t.data.relayed&&t.data.instanceId===s&&(n(t.data.body),o.abort())},{signal:o.signal}),e.postMessage({...a,instanceId:s},{targetOrigin:a.targetOrigin||"/"})});export{y as relay,b as sendViaRelay}; |
{ | ||
"name": "@plasmohq/messaging", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Type-safe, zero-config messaging library for modern browser extensions", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
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
Sorry, the diff of this file is not supported yet
31148