
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@solid-primitives/broadcast-channel
Advanced tools
Primitive to manage Broadcast Channel. The Broadcast Channel is a browser API that allows basic communication between browsing contexts (that is, windows, tabs, frames, or iframes) on the same origin.
npm install @solid-primitives/broadcast-channel
# or
yarn add @solid-primitives/broadcast-channel
# or
pnpm add @solid-primitives/broadcast-channel
makeBroadcastChannel
Creates a new BroadcastChannel instance for cross-tab communication.
The channel name is used to identify the channel. If a channel with the same name already exists, it will be returned instead of creating a new one.
Channel attempt closing the channel when the on owner cleanup. If there are multiple connected instances, the channel will not be closed until the last owner is removed.
Returns an object with the following properties:
onMessage
- a function to subscribe to messages from other tabspostMessage
- a function to send messages to other tabsclose
- a function to close the channelchannelName
- the name of the channelinstance
- the underlying BroadcastChannel instanceconst { postMessage } = makeBroadcastChannel("test_channel");
postMessage({ id: 2, message: "hi" });
// Another browsing context
const { onMessage } = makeBroadcastChannel("test_channel");
onMessage(({ data }) => {
console.log(data); // { id: 2, message: "hi" }
});
You can use the same channel easily across different components in the same context
const Component_1 = () => {
const { postMessage } = makeBroadcastChannel("river");
const onClick = () => {
postMessage("hi");
};
return <button onClick={onClick}>Send Message</button>;
};
const Component_2 = () => {
const { onMessage } = makeBroadcastChannel("river");
const [message, setMessage] = createSignal("");
onMessage(({ data }) => {
setMessage(data);
});
return <div>{message()}</div>;
};
const App = () => {
const { onMessage } = makeBroadcastChannel("river");
onMessage(({ data }) => {
console.log(data);
});
return (
<>
<Component_1 />
<Component_2 />
</>
);
};
createBroadcastChannel
Provedes the same functionality as makeBroadcastChannel
but instead of returning onMessage
function, it returns a message
signal accessor that updates when postMessage is fired from other contexts.
const { postMessage } = createBroadcastChannel("test_channel");
postMessage({ id: 2, message: "hi" });
// Another browsing context
const { message } = createBroadcastChannel("test_channel");
createEffect(
on(
message,
data => {
console.log(data); // { id: 2, message: "hi" }
},
{ defer: true },
),
);
makeBroadcastChannel
and createBroadcastChannel
allows you to pass type which determines what should be passed to postMessage
and what values message()
or event.data from onMessage
callback are.
const { onMessage, postMessage } = makeBroadcastChannel<string>("test_channel");
onMessage(({ data }) => {
data; // Type 'string'
});
postMessage("hi");
type TData = { id: number; message: string };
const { message, postMessage } = createBroadcastChannel<TData>("test_channel");
postMessage({ id: "wrong type", message: "hi" }); // ❌
// ^^^
// (property) id: number
// Type 'string' is not assignable to type 'number'.
postMessage({ id: 5, message: "hi" }); // ✅
createEffect(
on(
message,
data => {
consumeDataIncorrect(data!); // ❌
// ^^^
// Argument of type 'TData' is not assignable to parameter of type '{ id: string; message: string; }'.
// Types of property 'id' are incompatible.
// Type 'number' is not assignable to type 'string'.
consumeDataCorrect(data!); // ✅
},
{ defer: true },
),
);
const consumeDataIncorrect = (data: { id: string; message: string }) => {
console.log(data);
};
const consumeDataCorrect = (data: { id: number; message: string }) => {
console.log(data);
};
Here's a working example here: https://stackblitz.com/edit/vitejs-vite-5xren3?file=src%2Fmain.tsx
See CHANGELOG.md
FAQs
Primitives to manage Broadcast Channel API
The npm package @solid-primitives/broadcast-channel receives a total of 21 weekly downloads. As such, @solid-primitives/broadcast-channel popularity was classified as not popular.
We found that @solid-primitives/broadcast-channel demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.