Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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 207,795 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.