Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
eventsource-polyfill
Advanced tools
A browser polyfill for W3C EventSource (http://www.w3.org/TR/eventsource/)
The eventsource-polyfill npm package provides a polyfill for the EventSource API, which is used for receiving server-sent events (SSE). This is particularly useful for environments that do not natively support EventSource, such as older browsers.
Basic EventSource Connection
This feature allows you to establish a basic connection to a server that sends events. The code sample demonstrates how to create an EventSource instance and handle incoming messages.
const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.onmessage = function(event) {
console.log('New message:', event.data);
};
Handling Different Event Types
This feature allows you to listen for specific types of events sent by the server. The code sample shows how to add an event listener for a custom event type.
const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.addEventListener('customEvent', function(event) {
console.log('Custom event received:', event.data);
});
Error Handling
This feature provides a way to handle errors that may occur during the connection. The code sample demonstrates how to set up an error handler.
const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.onerror = function(event) {
console.error('Error occurred:', event);
};
The eventsource package is a robust implementation of the EventSource API for Node.js. It provides similar functionalities to eventsource-polyfill but is specifically designed for server-side use in Node.js environments.
The sse package is another implementation of server-sent events for Node.js. It offers a simple API for creating and managing SSE connections, similar to eventsource-polyfill, but is more focused on server-side applications.
FAQs
A browser polyfill for W3C EventSource (http://www.w3.org/TR/eventsource/)
The npm package eventsource-polyfill receives a total of 199,796 weekly downloads. As such, eventsource-polyfill popularity was classified as popular.
We found that eventsource-polyfill 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 now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.