Socket
Book a DemoInstallSign in
Socket

@firebase/performance

Package Overview
Dependencies
Maintainers
4
Versions
3008
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/performance - npm Package Compare versions

Comparing version

to
0.7.7-canary.25b60fdaa

dist/esm/index.esm.js

1

dist/esm/src/services/settings_service.d.ts

@@ -30,4 +30,5 @@ /**

configTimeToLive: number;
logMaxFlushSize: number;
getFlTransportFullUrl(): string;
static getInstance(): SettingsService;
}

5

dist/esm/src/services/transport_service.d.ts

@@ -25,5 +25,6 @@ /**

/**
* Force flush the queued events. Useful at page unload time to ensure all
* events are uploaded.
* Force flush the queued events. Useful at page unload time to ensure all events are uploaded.
* Flush will attempt to use sendBeacon to send events async and defaults back to fetch as soon as a
* sendBeacon fails. Firefox
*/
export declare function flushQueuedEvents(): void;

@@ -13,3 +13,3 @@ 'use strict';

const name = "@firebase/performance";
const version = "0.7.7-20250626140224";
const version = "0.7.7-canary.25b60fdaa";

@@ -335,2 +335,5 @@ /**

this.configTimeToLive = 12;
// The max number of events to send during a flush. This number is kept low to since Chrome has a
// shared payload limit for all sendBeacon calls in the same nav context.
this.logMaxFlushSize = 40;
}

@@ -376,3 +379,3 @@ getFlTransportFullUrl() {

const navigator = Api.getInstance().navigator;
if (navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker) {
if (navigator?.serviceWorker) {
if (navigator.serviceWorker.controller) {

@@ -446,4 +449,3 @@ return 2 /* ServiceWorkerStatus.CONTROLLED */;

function getAppId(firebaseApp) {
var _a;
const appId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.appId;
const appId = firebaseApp.options?.appId;
if (!appId) {

@@ -455,4 +457,3 @@ throw ERROR_FACTORY.create("no app id" /* ErrorCode.NO_APP_ID */);

function getProjectId(firebaseApp) {
var _a;
const projectId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.projectId;
const projectId = firebaseApp.options?.projectId;
if (!projectId) {

@@ -464,4 +465,3 @@ throw ERROR_FACTORY.create("no project id" /* ErrorCode.NO_PROJECT_ID */);

function getApiKey(firebaseApp) {
var _a;
const apiKey = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.apiKey;
const apiKey = firebaseApp.options?.apiKey;
if (!apiKey) {

@@ -525,3 +525,3 @@ throw ERROR_FACTORY.create("no api key" /* ErrorCode.NO_API_KEY */);

}
catch (_a) {
catch {
return;

@@ -628,2 +628,8 @@ }

}
if (entries.fpr_log_max_flush_size) {
settingsServiceInstance.logMaxFlushSize = Number(entries.fpr_log_max_flush_size);
}
else if (DEFAULT_CONFIGS.logMaxFlushSize) {
settingsServiceInstance.logMaxFlushSize = DEFAULT_CONFIGS.logMaxFlushSize;
}
// Set the per session trace and network logging flags.

@@ -719,2 +725,5 @@ settingsServiceInstance.logTraceAfterSampling = shouldLogAfterSampling(settingsServiceInstance.tracesSamplingRate);

const DEFAULT_REMAINING_TRIES = 3;
// Most browsers have a max payload of 64KB for sendbeacon/keep alive payload.
const MAX_SEND_BEACON_PAYLOAD_SIZE = 65536;
const TEXT_ENCODER = new TextEncoder();
let remainingTries = DEFAULT_REMAINING_TRIES;

@@ -747,9 +756,24 @@ /* eslint-enable camelcase */

const staged = queue.splice(0, MAX_EVENT_COUNT_PER_REQUEST);
const data = buildPayload(staged);
postToFlEndpoint(data)
.then(() => {
remainingTries = DEFAULT_REMAINING_TRIES;
})
.catch(() => {
// If the request fails for some reason, add the events that were attempted
// back to the primary queue to retry later.
queue = [...staged, ...queue];
remainingTries--;
consoleLogger.info(`Tries left: ${remainingTries}.`);
processQueue(DEFAULT_SEND_INTERVAL_MS);
});
}
function buildPayload(events) {
/* eslint-disable camelcase */
// We will pass the JSON serialized event to the backend.
const log_event = staged.map(evt => ({
const log_event = events.map(evt => ({
source_extension_json_proto3: evt.message,
event_time_ms: String(evt.eventTime)
}));
const data = {
const transportBatchLog = {
request_time_ms: String(Date.now()),

@@ -764,25 +788,19 @@ client_info: {

/* eslint-enable camelcase */
postToFlEndpoint(data)
.then(() => {
remainingTries = DEFAULT_REMAINING_TRIES;
})
.catch(() => {
// If the request fails for some reason, add the events that were attempted
// back to the primary queue to retry later.
queue = [...staged, ...queue];
remainingTries--;
consoleLogger.info(`Tries left: ${remainingTries}.`);
processQueue(DEFAULT_SEND_INTERVAL_MS);
});
return JSON.stringify(transportBatchLog);
}
function postToFlEndpoint(data) {
/** Sends to Firelog. Atempts to use sendBeacon otherwsise uses fetch. */
function postToFlEndpoint(body) {
const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
const body = JSON.stringify(data);
return navigator.sendBeacon && navigator.sendBeacon(flTransportFullUrl, body)
? Promise.resolve()
: fetch(flTransportFullUrl, {
const size = TEXT_ENCODER.encode(body).length;
if (size <= MAX_SEND_BEACON_PAYLOAD_SIZE &&
navigator.sendBeacon &&
navigator.sendBeacon(flTransportFullUrl, body)) {
return Promise.resolve();
}
else {
return fetch(flTransportFullUrl, {
method: 'POST',
body,
keepalive: true
}).then();
body
});
}
}

@@ -809,9 +827,30 @@ function addToQueue(evt) {

/**
* Force flush the queued events. Useful at page unload time to ensure all
* events are uploaded.
* Force flush the queued events. Useful at page unload time to ensure all events are uploaded.
* Flush will attempt to use sendBeacon to send events async and defaults back to fetch as soon as a
* sendBeacon fails. Firefox
*/
function flushQueuedEvents() {
const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
while (queue.length > 0) {
dispatchQueueEvents();
// Send the last events first to prioritize page load traces
const staged = queue.splice(-SettingsService.getInstance().logMaxFlushSize);
const body = buildPayload(staged);
if (navigator.sendBeacon &&
navigator.sendBeacon(flTransportFullUrl, body)) {
continue;
}
else {
queue = [...queue, ...staged];
break;
}
}
if (queue.length > 0) {
const body = buildPayload(queue);
fetch(flTransportFullUrl, {
method: 'POST',
body
}).catch(() => {
consoleLogger.info(`Failed flushing queued events.`);
});
}
}

@@ -1156,3 +1195,3 @@

if (options && options.attributes) {
this.customAttributes = Object.assign({}, options.attributes);
this.customAttributes = { ...options.attributes };
}

@@ -1191,3 +1230,3 @@ if (options && options.metrics) {

if (isValidMetricName(counter, this.name)) {
this.counters[counter] = convertMetricValueToInteger(numAsInteger !== null && numAsInteger !== void 0 ? numAsInteger : 0);
this.counters[counter] = convertMetricValueToInteger(numAsInteger ?? 0);
}

@@ -1246,3 +1285,3 @@ else {

getAttributes() {
return Object.assign({}, this.customAttributes);
return { ...this.customAttributes };
}

@@ -1384,20 +1423,17 @@ setStartTime(startTime) {

api.onLCP((metric) => {
var _a;
webVitalMetrics.lcp = {
value: metric.value,
elementAttribution: (_a = metric.attribution) === null || _a === void 0 ? void 0 : _a.element
elementAttribution: metric.attribution?.element
};
});
api.onCLS((metric) => {
var _a;
webVitalMetrics.cls = {
value: metric.value,
elementAttribution: (_a = metric.attribution) === null || _a === void 0 ? void 0 : _a.largestShiftTarget
elementAttribution: metric.attribution?.largestShiftTarget
};
});
api.onINP((metric) => {
var _a;
webVitalMetrics.inp = {
value: metric.value,
elementAttribution: (_a = metric.attribution) === null || _a === void 0 ? void 0 : _a.interactionTarget
elementAttribution: metric.attribution?.interactionTarget
};

@@ -1475,6 +1511,6 @@ });

}
if ((settings === null || settings === void 0 ? void 0 : settings.dataCollectionEnabled) !== undefined) {
if (settings?.dataCollectionEnabled !== undefined) {
this.dataCollectionEnabled = settings.dataCollectionEnabled;
}
if ((settings === null || settings === void 0 ? void 0 : settings.instrumentationEnabled) !== undefined) {
if (settings?.instrumentationEnabled !== undefined) {
this.instrumentationEnabled = settings.instrumentationEnabled;

@@ -1546,3 +1582,3 @@ }

const initialSettings = provider.getOptions();
if (util.deepEqual(initialSettings, settings !== null && settings !== void 0 ? settings : {})) {
if (util.deepEqual(initialSettings, settings ?? {})) {
return existingInstance;

@@ -1589,4 +1625,4 @@ }

app.registerVersion(name, version);
// BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
app.registerVersion(name, version, 'cjs2017');
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
app.registerVersion(name, version, 'cjs2020');
}

@@ -1593,0 +1629,0 @@ registerPerformance();

@@ -30,4 +30,5 @@ /**

configTimeToLive: number;
logMaxFlushSize: number;
getFlTransportFullUrl(): string;
static getInstance(): SettingsService;
}

@@ -25,5 +25,6 @@ /**

/**
* Force flush the queued events. Useful at page unload time to ensure all
* events are uploaded.
* Force flush the queued events. Useful at page unload time to ensure all events are uploaded.
* Flush will attempt to use sendBeacon to send events async and defaults back to fetch as soon as a
* sendBeacon fails. Firefox
*/
export declare function flushQueuedEvents(): void;
{
"name": "@firebase/performance",
"version": "0.7.7-20250626140224",
"version": "0.7.7-canary.25b60fdaa",
"description": "Firebase performance for web",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/esm/index.esm2017.js",
"module": "dist/esm/index.esm2017.js",
"browser": "dist/esm/index.esm.js",
"module": "dist/esm/index.esm.js",
"exports": {

@@ -13,3 +13,3 @@ ".": {

"require": "./dist/index.cjs.js",
"default": "./dist/esm/index.esm2017.js"
"default": "./dist/esm/index.esm.js"
},

@@ -39,9 +39,9 @@ "./package.json": "./package.json"

"peerDependencies": {
"@firebase/app": "0.13.2-20250626140224"
"@firebase/app": "0.13.2-canary.25b60fdaa"
},
"dependencies": {
"@firebase/logger": "0.4.4",
"@firebase/installations": "0.6.18-20250626140224",
"@firebase/util": "1.12.1-20250626140224",
"@firebase/component": "0.6.18-20250626140224",
"@firebase/logger": "0.4.4-canary.25b60fdaa",
"@firebase/installations": "0.6.18-canary.25b60fdaa",
"@firebase/util": "1.12.1-canary.25b60fdaa",
"@firebase/component": "0.6.18-canary.25b60fdaa",
"tslib": "^2.1.0",

@@ -52,3 +52,3 @@ "web-vitals": "^4.2.4"

"devDependencies": {
"@firebase/app": "0.13.2-20250626140224",
"@firebase/app": "0.13.2-canary.25b60fdaa",
"rollup": "2.79.2",

@@ -55,0 +55,0 @@ "@rollup/plugin-json": "6.1.0",

Sorry, the diff of this file is not supported yet