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

@splitsoftware/browser-rum-agent

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@splitsoftware/browser-rum-agent - npm Package Compare versions

Comparing version 0.7.1 to 1.0.0-rc.0

cjs/utils/validateEventCollectorsOption.js

7

CHANGES.txt

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

1.0.0 (November XX, 2024)
- Added a new configuration option called `eventCollectors` to disable or configure the registration of event collectors.
- Updated some transitive dependencies for vulnerability fixes.
- Bugfixing - Handle `Navigator.sendBeacon` API exceptions, and fallback to regular Fetch/XHR transport in case of error.
- BREAKING CHANGES:
- Removed `webVitals` event collector from the default import. It is now registered by default.
0.7.1 (May 16, 2024)

@@ -2,0 +9,0 @@ - Bugfixing - Fixed an issue in the `SplitRumAgent.setup` method where the default `prefix` option was being overwritten by undefined when not provided in the config object parameter.

21

cjs/config.js

@@ -8,9 +8,22 @@ "use strict";

var navigation_1 = require("./metrics/navigation");
var webVitals_1 = require("./metrics/webVitals");
// IIFE to avoid tree-shaking of default event collectors
exports.SplitRumAgent = (function (SplitRumAgent) {
if (config_1.isBrowser) {
SplitRumAgent.register((0, errors_1.errors)());
SplitRumAgent.register((0, navigation_1.navigationTiming)());
}
var registerEventCollectors = true;
var slimSetup = SplitRumAgent.setup;
SplitRumAgent.setup = function setup(sdkKey, config) {
slimSetup(sdkKey, config);
if (config_1.isBrowser && registerEventCollectors) {
registerEventCollectors = false;
var eventCollectors = SplitRumAgent.__getConfig().eventCollectors;
if (eventCollectors.errors)
SplitRumAgent.register((0, errors_1.errors)());
if (eventCollectors.navigationTiming)
SplitRumAgent.register((0, navigation_1.navigationTiming)());
if (eventCollectors.webVitals)
SplitRumAgent.register((0, webVitals_1.webVitals)(eventCollectors.webVitals === true ? undefined : eventCollectors.webVitals));
}
return SplitRumAgent;
};
return SplitRumAgent;
})(config_1.globalRef.SplitRumAgent);

4

cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.webVitals = exports.routeChanges = exports.tti = exports.SplitRumAgent = void 0;
exports.routeChanges = exports.tti = exports.SplitRumAgent = void 0;
// Create SplitRumAgent namespace and export it for ESM/CJS imports

@@ -13,3 +13,1 @@ // Must use a named import to create the SplitRumAgent namespace (side effects)

Object.defineProperty(exports, "routeChanges", { enumerable: true, get: function () { return routeChanges_1.routeChanges; } });
var webVitals_1 = require("./metrics/webVitals");
Object.defineProperty(exports, "webVitals", { enumerable: true, get: function () { return webVitals_1.webVitals; } });

@@ -43,3 +43,3 @@ "use strict";

/**
* web-vitals metrics
* Captures web-vitals metrics
*/

@@ -46,0 +46,0 @@ function webVitals(options) {

@@ -17,2 +17,3 @@ "use strict";

var errors_1 = require("../metrics/errors");
var validateEventCollectorsOption_1 = require("../utils/validateEventCollectorsOption");
// Browser support:

@@ -37,3 +38,4 @@ // - ES5 syntax

log: log_1.log,
userConsent: constants_1.CONSENT_GRANTED, // User consent is assumed to be granted by default
userConsent: constants_1.CONSENT_GRANTED,
eventCollectors: {},
};

@@ -44,3 +46,3 @@ var _isConfigured = false;

_isConfigured = true;
// always async never inasync ;)
// async in case multiple addIdentity calls are made in the same tick
setTimeout(queue_1.flush, 0);

@@ -68,2 +70,3 @@ }

_config.userConsent = userConsent;
_config.eventCollectors = (0, validateEventCollectorsOption_1.validateEventCollectorsOption)(config);
}

@@ -70,0 +73,0 @@ if ((0, isString_1.isString)(sdkKey)) {

@@ -5,4 +5,3 @@ "use strict";

index_1.SplitRumAgent.routeChanges = index_1.routeChanges;
index_1.SplitRumAgent.webVitals = index_1.webVitals;
// eslint-disable-next-line import/no-default-export
exports.default = index_1.SplitRumAgent;

@@ -38,2 +38,2 @@ "use strict";

exports.userAgent = getUserAgent();
exports.languageVersion = 'jsrum-' + '0.7.1';
exports.languageVersion = 'jsrum-' + '1.0.0-rc.0';

@@ -31,5 +31,12 @@ "use strict";

&& typeof navigator === 'object' && navigator.sendBeacon; // and that it exists
return useBeacon ?
navigator.sendBeacon(url, stringifiedData) :
fallbackPost(url, stringifiedData);
if (useBeacon) {
// https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
try {
useBeacon = navigator.sendBeacon(url, stringifiedData);
}
catch (e) {
useBeacon = false;
}
}
return useBeacon || fallbackPost(url, stringifiedData);
}

@@ -36,0 +43,0 @@ exports.post = post;

@@ -5,9 +5,22 @@ import { globalRef, isBrowser } from './slim/config';

import { navigationTiming } from './metrics/navigation';
import { webVitals } from './metrics/webVitals';
// IIFE to avoid tree-shaking of default event collectors
export var SplitRumAgent = (function (SplitRumAgent) {
if (isBrowser) {
SplitRumAgent.register(errors());
SplitRumAgent.register(navigationTiming());
}
var registerEventCollectors = true;
var slimSetup = SplitRumAgent.setup;
SplitRumAgent.setup = function setup(sdkKey, config) {
slimSetup(sdkKey, config);
if (isBrowser && registerEventCollectors) {
registerEventCollectors = false;
var eventCollectors = SplitRumAgent.__getConfig().eventCollectors;
if (eventCollectors.errors)
SplitRumAgent.register(errors());
if (eventCollectors.navigationTiming)
SplitRumAgent.register(navigationTiming());
if (eventCollectors.webVitals)
SplitRumAgent.register(webVitals(eventCollectors.webVitals === true ? undefined : eventCollectors.webVitals));
}
return SplitRumAgent;
};
return SplitRumAgent;
})(globalRef.SplitRumAgent);

@@ -7,2 +7,1 @@ // Create SplitRumAgent namespace and export it for ESM/CJS imports

export { routeChanges } from './metrics/routeChanges';
export { webVitals } from './metrics/webVitals';

@@ -16,3 +16,3 @@ // webVitals plugin uses the web-vital standard build.

/**
* web-vitals metrics
* Captures web-vitals metrics
*/

@@ -19,0 +19,0 @@ export function webVitals(options) {

@@ -14,2 +14,3 @@ import { setSchedule, flush, track, queue } from '../utils/queue';

import { handleCustomErrors } from '../metrics/errors';
import { validateEventCollectorsOption } from '../utils/validateEventCollectorsOption';
// Browser support:

@@ -34,3 +35,4 @@ // - ES5 syntax

log: log,
userConsent: CONSENT_GRANTED, // User consent is assumed to be granted by default
userConsent: CONSENT_GRANTED,
eventCollectors: {},
};

@@ -41,3 +43,3 @@ var _isConfigured = false;

_isConfigured = true;
// always async never inasync ;)
// async in case multiple addIdentity calls are made in the same tick
setTimeout(flush, 0);

@@ -65,2 +67,3 @@ }

_config.userConsent = userConsent;
_config.eventCollectors = validateEventCollectorsOption(config);
}

@@ -67,0 +70,0 @@ if (isString(sdkKey)) {

@@ -1,5 +0,4 @@

import { SplitRumAgent, routeChanges, webVitals } from './index';
import { SplitRumAgent, routeChanges } from './index';
SplitRumAgent.routeChanges = routeChanges;
SplitRumAgent.webVitals = webVitals;
// eslint-disable-next-line import/no-default-export
export default SplitRumAgent;

@@ -31,2 +31,2 @@ /* eslint-disable compat/compat */

export var userAgent = getUserAgent();
export var languageVersion = 'jsrum-' + '0.7.1';
export var languageVersion = 'jsrum-' + '1.0.0-rc.0';

@@ -27,5 +27,12 @@ import { assignIdentities } from './assign';

&& typeof navigator === 'object' && navigator.sendBeacon; // and that it exists
return useBeacon ?
navigator.sendBeacon(url, stringifiedData) :
fallbackPost(url, stringifiedData);
if (useBeacon) {
// https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
try {
useBeacon = navigator.sendBeacon(url, stringifiedData);
}
catch (e) {
useBeacon = false;
}
}
return useBeacon || fallbackPost(url, stringifiedData);
}

@@ -32,0 +39,0 @@ // Fetch and XHR request fallback. Exporting only for UT purposes.

{
"name": "@splitsoftware/browser-rum-agent",
"version": "0.7.1",
"version": "1.0.0-rc.0",
"description": "Split Software RUM Agent for Browsers.",

@@ -5,0 +5,0 @@ "main": "cjs/index.js",

@@ -23,8 +23,8 @@ # Split Browser RUM Agent

// Configure
SplitRumAgent
.setup('YOUR_SDK_KEY')
.addIdentity({
key: 'USER_ID',
trafficType: 'user'
})
SplitRumAgent.setup('YOUR_SDK_KEY')
SplitRumAgent.addIdentity({
key: 'USER_ID',
trafficType: 'user'
})
```

@@ -55,3 +55,3 @@

* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
* Node.js [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)

@@ -58,0 +58,0 @@ * PHP thin-client [Github](https://github.com/splitio/php-thin-client) [Docs](https://help.split.io/hc/en-us/articles/18305128673933-PHP-Thin-Client-SDK)

@@ -105,3 +105,29 @@ /* eslint-disable no-use-before-define */

*/
userConsent?: ConsentStatus
userConsent?: ConsentStatus,
/**
* Optional object to configure the registration of event collectors in the RUM agent.
*
* This configuration is ignored when using the slim version of the RUM agent (i.e., `import { SplitRumAgent } from '@splitsoftware/browser-rum-agent/slim'`), as no event collectors are registered by default.
*/
eventCollectors?: {
/**
* Whether to register `error` events or not.
*
* @defaultValue `true`
*/
errors?: boolean,
/**
* Whether to register navigation timing events, i.e., `page.load.time` and `time.to.dom.interactive` events.
*
* @defaultValue `true`
*/
navigationTiming?: boolean,
/**
* Whether to register Web-Vitals events or not. If an object is provided, it will be used as the configuration for the Web-Vitals event collector.
*
* @defaultValue `true`
* @see {@link https://help.split.io/hc/en-us/articles/360030898431-Browser-RUM-Agent#web-vitals}
*/
webVitals?: boolean | IWebVitalsOptions
}
};

@@ -345,39 +371,1 @@

}
/**
* Collects Web-Vitals metrics ({@link https://www.npmjs.com/package/web-vitals}).
*
* By default it collects all web-vitals metrics, but you can specify which ones to collect by passing a `reportOptions` object.
*
* For example:
* ```
* SplitRumAgent.register(webVitals({
* reportOptions: {
* // collects only the core web-vitals
* onCLS: true,
* onFID: true,
* onLCP: true,
* // other web-vital metrics are not collected
* }
* }));
* ```
*
* Collected event format:
* ```
* {
* eventTypeId: 'webvitals.cls' | 'webvitals.fcp' | 'webvitals.fid' | 'webvitals.inp' | 'webvitals.lcp' | 'webvitals.ttfb',
* value: number,
* properties: {
* rating: 'good' | 'needsImprovement' | 'poor',
* navigationType: 'navigate' | 'reload' | 'back_forward' | 'back-forward-cache' | 'prerender' | 'restore'
* }
* }
* ```
*
* @param options - Collector options.
* @defaultValue
* ```
* { reportOptions: { onCLS: true, onFCP: true, onFID: true, onINP: true, onLCP: true, onTTFB: true } }
* ```
*/
export declare function webVitals(options?: IWebVitalsOptions): EventCollector;

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

import { EventCollector } from '../index';
import { EventCollector, IWebVitalsOptions } from '../index';

@@ -17,4 +17,3 @@ export {

routeChanges,
tti,
webVitals
tti
} from '../index';

@@ -70,1 +69,39 @@

export declare function navigationTiming(): EventCollector;
/**
* Collects Web-Vitals metrics ({@link https://www.npmjs.com/package/web-vitals}).
*
* By default it collects all web-vitals metrics, but you can specify which ones to collect by passing a `reportOptions` object.
*
* For example:
* ```
* SplitRumAgent.register(webVitals({
* reportOptions: {
* // collects only the core web-vitals
* onCLS: true,
* onFID: true,
* onLCP: true,
* // other web-vital metrics are not collected
* }
* }));
* ```
*
* Collected event format:
* ```
* {
* eventTypeId: 'webvitals.cls' | 'webvitals.fcp' | 'webvitals.fid' | 'webvitals.inp' | 'webvitals.lcp' | 'webvitals.ttfb',
* value: number,
* properties: {
* rating: 'good' | 'needsImprovement' | 'poor',
* navigationType: 'navigate' | 'reload' | 'back_forward' | 'back-forward-cache' | 'prerender' | 'restore'
* }
* }
* ```
*
* @param options - Collector options.
* @defaultValue
* ```
* { reportOptions: { onCLS: true, onFCP: true, onFID: true, onINP: true, onLCP: true, onTTFB: true } }
* ```
*/
export declare function webVitals(options?: IWebVitalsOptions): EventCollector;
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