@rudderstack/analytics-js 3.26.0 → 3.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/npm/legacy/bundled/cjs/index.cjs +24 -19
- package/dist/npm/legacy/bundled/esm/index.mjs +24 -19
- package/dist/npm/legacy/bundled/umd/index.js +24 -19
- package/dist/npm/legacy/cjs/index.cjs +24 -19
- package/dist/npm/legacy/content-script/cjs/index.cjs +24 -19
- package/dist/npm/legacy/content-script/esm/index.mjs +24 -19
- package/dist/npm/legacy/content-script/umd/index.js +24 -19
- package/dist/npm/legacy/esm/index.mjs +24 -19
- package/dist/npm/legacy/umd/index.js +24 -19
- package/dist/npm/modern/bundled/cjs/index.cjs +23 -18
- package/dist/npm/modern/bundled/esm/index.mjs +23 -18
- package/dist/npm/modern/bundled/umd/index.js +23 -18
- package/dist/npm/modern/cjs/index.cjs +22 -17
- package/dist/npm/modern/content-script/cjs/index.cjs +23 -18
- package/dist/npm/modern/content-script/esm/index.mjs +23 -18
- package/dist/npm/modern/content-script/umd/index.js +23 -18
- package/dist/npm/modern/esm/index.mjs +22 -17
- package/dist/npm/modern/umd/index.js +22 -17
- package/package.json +1 -1
|
@@ -910,7 +910,7 @@ error.stack="".concat(stack,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case sta
|
|
|
910
910
|
error.stacktrace="".concat(stacktrace,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case operaSourceloc:default:// eslint-disable-next-line no-param-reassign
|
|
911
911
|
error['opera#sourceloc']="".concat(operaSourceloc,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;}}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
912
912
|
|
|
913
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.
|
|
913
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.28.0';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
914
914
|
|
|
915
915
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
916
916
|
|
|
@@ -1133,7 +1133,7 @@ try{if(JSON.stringify(f)==='{}')return accum;return accum.concat(f);}catch(_unus
|
|
|
1133
1133
|
* Utility to parse XHR JSON response
|
|
1134
1134
|
*/var responseTextToJson=function responseTextToJson(responseText,onError){try{return JSON.parse(responseText||'');}catch(err){var error=getMutatedError(err,'Failed to parse response data');onError(error);}return undefined;};
|
|
1135
1135
|
|
|
1136
|
-
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);
|
|
1136
|
+
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);var INTEGRATIONS_ERROR_CATEGORY='integrations';var SDK_ERROR_CATEGORY='sdk';var DEFAULT_ERROR_CATEGORY=SDK_ERROR_CATEGORY;
|
|
1137
1137
|
|
|
1138
1138
|
var DEFAULT_XHR_REQUEST_OPTIONS={headers:{Accept:'application/json','Content-Type':'application/json;charset=UTF-8'},method:'GET'};/**
|
|
1139
1139
|
* Utility to create request configuration based on default options
|
|
@@ -1169,7 +1169,7 @@ var SDK_FILE_NAME_PREFIXES=function SDK_FILE_NAME_PREFIXES(){return ['rsa'// Pre
|
|
|
1169
1169
|
// Potential PII or sensitive data
|
|
1170
1170
|
var APP_STATE_EXCLUDE_KEYS=['userId','userTraits','groupId','groupTraits','anonymousId','config','integration',// integration instance objects
|
|
1171
1171
|
'eventBuffer',// pre-load event buffer (may contain PII)
|
|
1172
|
-
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1172
|
+
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1173
1173
|
|
|
1174
1174
|
var detectAdBlockers=function detectAdBlockers(httpClient){state.capabilities.isAdBlockerDetectionInProgress.value=true;try{// Apparently, '?view=ad' is a query param that is blocked by majority of adblockers
|
|
1175
1175
|
// Use source config URL here as it is very unlikely to be blocked by adblockers
|
|
@@ -1213,23 +1213,27 @@ if(state.capabilities.cspBlockedURLs.value.includes(extractedURL)){resolve(false
|
|
|
1213
1213
|
checkIfAdBlockersAreActive(state,httpClient,resolve);}}else {// Filter out errors that are not from the RS CDN.
|
|
1214
1214
|
resolve(false);}}else {// Allow the error to be notified if no URL could be extracted from the error message
|
|
1215
1215
|
resolve(true);}}else {resolve(!ERROR_MESSAGES_TO_BE_FILTERED.some(function(e){return e.test(errMsg);}));}});};/**
|
|
1216
|
+
* A function to get the directory name from a file path.
|
|
1217
|
+
* @param {string} filePath The file path
|
|
1218
|
+
* @returns The directory name or undefined if the file path is invalid
|
|
1219
|
+
*/var getDirectoryName=function getDirectoryName(filePath){if(!filePath){return undefined;}var paths=filePath.split('/');return paths.at(-2);};/**
|
|
1220
|
+
* A function to get the top stack path from the exception.
|
|
1221
|
+
* @param {Exception} exception The exception object
|
|
1222
|
+
* @returns The top stack path or undefined if the exception is invalid
|
|
1223
|
+
*/var getTopStackPath=function getTopStackPath(exception){var _exception$stacktrace;var errorOrigin=(_exception$stacktrace=exception.stacktrace[0])===null||_exception$stacktrace===void 0?void 0:_exception$stacktrace.file;if(!errorOrigin||typeof errorOrigin!=='string'){return undefined;}return errorOrigin;};/**
|
|
1216
1224
|
* A function to determine if the error is from Rudder SDK
|
|
1217
1225
|
* @param {Error} exception
|
|
1218
1226
|
* @returns
|
|
1219
|
-
*/var isSDKError=function isSDKError(exception){var
|
|
1220
|
-
// Ex: parentFolderName will be 'sample' for url: https://example.com/sample/file.min.js
|
|
1221
|
-
var parentFolderName=paths[paths.length-2];return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category!==null&&category!==void 0?category:DEFAULT_ERROR_CATEGORY},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1227
|
+
*/var isSDKError=function isSDKError(exception){var errorOrigin=getTopStackPath(exception);if(!errorOrigin){return false;}var srcFileName=errorOrigin.substring(errorOrigin.lastIndexOf('/')+1);var parentFolderName=getDirectoryName(errorOrigin);return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorCategory=function getErrorCategory(exception,category){if(category){return category;}var errorOrigin=getTopStackPath(exception);var directoryName=getDirectoryName(errorOrigin);if(directoryName===CDN_INT_DIR){return INTEGRATIONS_ERROR_CATEGORY;}return DEFAULT_ERROR_CATEGORY;};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1222
1228
|
* A function to get the grouping hash value to be used for the error event.
|
|
1223
|
-
* Grouping hash is suppressed for non-cdn installs.
|
|
1224
1229
|
* If the grouping hash is an error instance, the normalized error message is used as the grouping hash.
|
|
1225
1230
|
* If the grouping hash is an empty string or not specified, the default grouping hash is used.
|
|
1226
1231
|
* If the grouping hash is a string, it is used as is.
|
|
1227
1232
|
* @param curErrGroupingHash The grouping hash value part of the error event
|
|
1228
1233
|
* @param defaultGroupingHash The default grouping hash value. It is the error message.
|
|
1229
|
-
* @param state The application state
|
|
1230
1234
|
* @param logger The logger instance
|
|
1231
1235
|
* @returns The final grouping hash value to be used for the error event
|
|
1232
|
-
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,
|
|
1236
|
+
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,logger){var normalizedGroupingHash;if(!isDefined(curErrGroupingHash)){normalizedGroupingHash=defaultGroupingHash;}else if(isString(curErrGroupingHash)){normalizedGroupingHash=curErrGroupingHash;}else {var normalizedErrorInstance=normalizeError(curErrGroupingHash,logger);if(isDefined(normalizedErrorInstance)){normalizedGroupingHash=normalizedErrorInstance.message;}else {normalizedGroupingHash=defaultGroupingHash;}}return normalizedGroupingHash;};
|
|
1233
1237
|
|
|
1234
1238
|
/**
|
|
1235
1239
|
* A service to handle errors
|
|
@@ -1250,18 +1254,18 @@ document.addEventListener('securitypolicyviolation',function(event){var blockedU
|
|
|
1250
1254
|
* @param errorInfo.errorType - The type of the error (handled or unhandled)
|
|
1251
1255
|
* @param errorInfo.groupingHash - The grouping hash of the error
|
|
1252
1256
|
* @param errorInfo.category - The category of the error (sdk or integrations)
|
|
1253
|
-
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1257
|
+
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,errorCategory,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1254
1258
|
// In case of NPM installations, the unhandled errors from the SDK cannot be identified
|
|
1255
1259
|
// and will NOT be reported unless they occur in plugins or integrations.
|
|
1256
|
-
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};//
|
|
1257
|
-
//
|
|
1258
|
-
//
|
|
1260
|
+
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};// This will allow custom grouping of errors.
|
|
1261
|
+
// In case of NPM installations, the default grouping by surrounding code
|
|
1262
|
+
// does not make sense as each user application is different and will create a lot of noise in the alerts.
|
|
1259
1263
|
// References:
|
|
1260
1264
|
// https://docs.bugsnag.com/platforms/javascript/customizing-error-reports/#groupinghash
|
|
1261
1265
|
// https://docs.bugsnag.com/product/error-grouping/#user_defined
|
|
1262
|
-
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,
|
|
1263
|
-
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);// send it to metrics service
|
|
1264
|
-
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,
|
|
1266
|
+
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,this.logger);// Get the final payload to be sent to the metrics service
|
|
1267
|
+
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);errorCategory=getErrorCategory(bsException,category);// send it to metrics service
|
|
1268
|
+
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,errorCategory),sendRawData:true},isRawResponse:true});}case 4:// Log handled errors and errors dispatched by the SDK
|
|
1265
1269
|
if(errorType===ErrorType.HANDLEDEXCEPTION||isSdkDispatched){this.logger.error(bsException.message);}_context.n=6;break;case 5:_context.p=5;_t=_context.v;// If an error occurs while handling an error, log it
|
|
1266
1270
|
this.logger.error(HANDLE_ERROR_FAILURE(ERROR_HANDLER),_t);case 6:return _context.a(2);}},_callee,this,[[0,5]]);}));function onError(_x){return _onError.apply(this,arguments);}return onError;}()/**
|
|
1267
1271
|
* Add breadcrumbs to add insight of a user's journey before an error
|
|
@@ -1347,7 +1351,7 @@ var userIdKey='rl_user_id';var userTraitsKey='rl_trait';var anonymousUserIdKey='
|
|
|
1347
1351
|
var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};
|
|
1348
1352
|
|
|
1349
1353
|
var EVENT_PAYLOAD_SIZE_BYTES_LIMIT=32*1024;// 32 KB
|
|
1350
|
-
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1354
|
+
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1351
1355
|
|
|
1352
1356
|
var isStorageQuotaExceeded=function isStorageQuotaExceeded(e){var matchingNames=['QuotaExceededError','NS_ERROR_DOM_QUOTA_REACHED'];// Everything except Firefox, Firefox
|
|
1353
1357
|
var matchingCodes=[22,1014];if(e instanceof DOMException){return matchingNames.includes(e.name)||matchingCodes.includes(e.code);}return false;};// TODO: also check for SecurityErrors
|
|
@@ -3301,7 +3305,8 @@ this.swapQueueStoreToInMemoryEngine();// and save it there
|
|
|
3301
3305
|
this.set(key,value);}else {var customMessage=STORE_DATA_SAVE_ERROR(key);this.onError(err,customMessage,customMessage);}}}/**
|
|
3302
3306
|
* Get by Key.
|
|
3303
3307
|
*/},{key:"get",value:function get(key){var validKey=this.createValidKey(key);var decryptedValue;try{if(!validKey){return null;}decryptedValue=this.decrypt(this.engine.getItem(validKey));if(isNullOrUndefined(decryptedValue)||decryptedValue===''){return null;}// storejs that is used in localstorage engine already deserializes json strings but swallows errors
|
|
3304
|
-
return JSON.parse(decryptedValue);}catch(err){var
|
|
3308
|
+
return JSON.parse(decryptedValue);}catch(err){var encryptionPluginName=state.storage.encryptionPluginName.value;// Skip error reporting only when the encryption plugin is configured but failed to load
|
|
3309
|
+
var shouldReportError=!encryptionPluginName||!state.plugins.failedPlugins.value.includes(encryptionPluginName);if(shouldReportError){var customMessage=STORE_DATA_FETCH_ERROR(key);this.onError(err,customMessage,customMessage);}return null;}}/**
|
|
3305
3310
|
* Remove by Key.
|
|
3306
3311
|
*/},{key:"remove",value:function remove(key){var validKey=this.createValidKey(key);if(validKey){this.engine.removeItem(validKey);}}/**
|
|
3307
3312
|
* Get original engine
|
|
@@ -3985,7 +3990,7 @@ E(function(){var areAllDestinationsReady=totalDestinationsToLoad===0||state.nati
|
|
|
3985
3990
|
*/// eslint-disable-next-line class-methods-use-this
|
|
3986
3991
|
},{key:"onDestinationsReady",value:function onDestinationsReady(){// May be do any destination specific actions here
|
|
3987
3992
|
// Mark the ready status if not already done
|
|
3988
|
-
if(state.lifecycle.status.value!=='ready'){state.lifecycle.status.value='ready';}}// End lifecycle methods
|
|
3993
|
+
if(state.lifecycle.status.value!=='ready'){r(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
3989
3994
|
// Start consumer exposed methods
|
|
3990
3995
|
},{key:"ready",value:function ready(callback){var type='ready';if(!state.lifecycle.loaded.value){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
3991
3996
|
* If destinations are loaded or no integration is available for loading
|
|
@@ -908,7 +908,7 @@ error.stack="".concat(stack,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case sta
|
|
|
908
908
|
error.stacktrace="".concat(stacktrace,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case operaSourceloc:default:// eslint-disable-next-line no-param-reassign
|
|
909
909
|
error['opera#sourceloc']="".concat(operaSourceloc,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;}}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
910
910
|
|
|
911
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.
|
|
911
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.28.0';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
912
912
|
|
|
913
913
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
914
914
|
|
|
@@ -1131,7 +1131,7 @@ try{if(JSON.stringify(f)==='{}')return accum;return accum.concat(f);}catch(_unus
|
|
|
1131
1131
|
* Utility to parse XHR JSON response
|
|
1132
1132
|
*/var responseTextToJson=function responseTextToJson(responseText,onError){try{return JSON.parse(responseText||'');}catch(err){var error=getMutatedError(err,'Failed to parse response data');onError(error);}return undefined;};
|
|
1133
1133
|
|
|
1134
|
-
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);
|
|
1134
|
+
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);var INTEGRATIONS_ERROR_CATEGORY='integrations';var SDK_ERROR_CATEGORY='sdk';var DEFAULT_ERROR_CATEGORY=SDK_ERROR_CATEGORY;
|
|
1135
1135
|
|
|
1136
1136
|
var DEFAULT_XHR_REQUEST_OPTIONS={headers:{Accept:'application/json','Content-Type':'application/json;charset=UTF-8'},method:'GET'};/**
|
|
1137
1137
|
* Utility to create request configuration based on default options
|
|
@@ -1167,7 +1167,7 @@ var SDK_FILE_NAME_PREFIXES=function SDK_FILE_NAME_PREFIXES(){return ['rsa'// Pre
|
|
|
1167
1167
|
// Potential PII or sensitive data
|
|
1168
1168
|
var APP_STATE_EXCLUDE_KEYS=['userId','userTraits','groupId','groupTraits','anonymousId','config','integration',// integration instance objects
|
|
1169
1169
|
'eventBuffer',// pre-load event buffer (may contain PII)
|
|
1170
|
-
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1170
|
+
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1171
1171
|
|
|
1172
1172
|
var detectAdBlockers=function detectAdBlockers(httpClient){state.capabilities.isAdBlockerDetectionInProgress.value=true;try{// Apparently, '?view=ad' is a query param that is blocked by majority of adblockers
|
|
1173
1173
|
// Use source config URL here as it is very unlikely to be blocked by adblockers
|
|
@@ -1211,23 +1211,27 @@ if(state.capabilities.cspBlockedURLs.value.includes(extractedURL)){resolve(false
|
|
|
1211
1211
|
checkIfAdBlockersAreActive(state,httpClient,resolve);}}else {// Filter out errors that are not from the RS CDN.
|
|
1212
1212
|
resolve(false);}}else {// Allow the error to be notified if no URL could be extracted from the error message
|
|
1213
1213
|
resolve(true);}}else {resolve(!ERROR_MESSAGES_TO_BE_FILTERED.some(function(e){return e.test(errMsg);}));}});};/**
|
|
1214
|
+
* A function to get the directory name from a file path.
|
|
1215
|
+
* @param {string} filePath The file path
|
|
1216
|
+
* @returns The directory name or undefined if the file path is invalid
|
|
1217
|
+
*/var getDirectoryName=function getDirectoryName(filePath){if(!filePath){return undefined;}var paths=filePath.split('/');return paths.at(-2);};/**
|
|
1218
|
+
* A function to get the top stack path from the exception.
|
|
1219
|
+
* @param {Exception} exception The exception object
|
|
1220
|
+
* @returns The top stack path or undefined if the exception is invalid
|
|
1221
|
+
*/var getTopStackPath=function getTopStackPath(exception){var _exception$stacktrace;var errorOrigin=(_exception$stacktrace=exception.stacktrace[0])===null||_exception$stacktrace===void 0?void 0:_exception$stacktrace.file;if(!errorOrigin||typeof errorOrigin!=='string'){return undefined;}return errorOrigin;};/**
|
|
1214
1222
|
* A function to determine if the error is from Rudder SDK
|
|
1215
1223
|
* @param {Error} exception
|
|
1216
1224
|
* @returns
|
|
1217
|
-
*/var isSDKError=function isSDKError(exception){var
|
|
1218
|
-
// Ex: parentFolderName will be 'sample' for url: https://example.com/sample/file.min.js
|
|
1219
|
-
var parentFolderName=paths[paths.length-2];return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category!==null&&category!==void 0?category:DEFAULT_ERROR_CATEGORY},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1225
|
+
*/var isSDKError=function isSDKError(exception){var errorOrigin=getTopStackPath(exception);if(!errorOrigin){return false;}var srcFileName=errorOrigin.substring(errorOrigin.lastIndexOf('/')+1);var parentFolderName=getDirectoryName(errorOrigin);return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorCategory=function getErrorCategory(exception,category){if(category){return category;}var errorOrigin=getTopStackPath(exception);var directoryName=getDirectoryName(errorOrigin);if(directoryName===CDN_INT_DIR){return INTEGRATIONS_ERROR_CATEGORY;}return DEFAULT_ERROR_CATEGORY;};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1220
1226
|
* A function to get the grouping hash value to be used for the error event.
|
|
1221
|
-
* Grouping hash is suppressed for non-cdn installs.
|
|
1222
1227
|
* If the grouping hash is an error instance, the normalized error message is used as the grouping hash.
|
|
1223
1228
|
* If the grouping hash is an empty string or not specified, the default grouping hash is used.
|
|
1224
1229
|
* If the grouping hash is a string, it is used as is.
|
|
1225
1230
|
* @param curErrGroupingHash The grouping hash value part of the error event
|
|
1226
1231
|
* @param defaultGroupingHash The default grouping hash value. It is the error message.
|
|
1227
|
-
* @param state The application state
|
|
1228
1232
|
* @param logger The logger instance
|
|
1229
1233
|
* @returns The final grouping hash value to be used for the error event
|
|
1230
|
-
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,
|
|
1234
|
+
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,logger){var normalizedGroupingHash;if(!isDefined(curErrGroupingHash)){normalizedGroupingHash=defaultGroupingHash;}else if(isString(curErrGroupingHash)){normalizedGroupingHash=curErrGroupingHash;}else {var normalizedErrorInstance=normalizeError(curErrGroupingHash,logger);if(isDefined(normalizedErrorInstance)){normalizedGroupingHash=normalizedErrorInstance.message;}else {normalizedGroupingHash=defaultGroupingHash;}}return normalizedGroupingHash;};
|
|
1231
1235
|
|
|
1232
1236
|
/**
|
|
1233
1237
|
* A service to handle errors
|
|
@@ -1248,18 +1252,18 @@ document.addEventListener('securitypolicyviolation',function(event){var blockedU
|
|
|
1248
1252
|
* @param errorInfo.errorType - The type of the error (handled or unhandled)
|
|
1249
1253
|
* @param errorInfo.groupingHash - The grouping hash of the error
|
|
1250
1254
|
* @param errorInfo.category - The category of the error (sdk or integrations)
|
|
1251
|
-
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1255
|
+
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,errorCategory,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1252
1256
|
// In case of NPM installations, the unhandled errors from the SDK cannot be identified
|
|
1253
1257
|
// and will NOT be reported unless they occur in plugins or integrations.
|
|
1254
|
-
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};//
|
|
1255
|
-
//
|
|
1256
|
-
//
|
|
1258
|
+
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};// This will allow custom grouping of errors.
|
|
1259
|
+
// In case of NPM installations, the default grouping by surrounding code
|
|
1260
|
+
// does not make sense as each user application is different and will create a lot of noise in the alerts.
|
|
1257
1261
|
// References:
|
|
1258
1262
|
// https://docs.bugsnag.com/platforms/javascript/customizing-error-reports/#groupinghash
|
|
1259
1263
|
// https://docs.bugsnag.com/product/error-grouping/#user_defined
|
|
1260
|
-
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,
|
|
1261
|
-
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);// send it to metrics service
|
|
1262
|
-
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,
|
|
1264
|
+
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,this.logger);// Get the final payload to be sent to the metrics service
|
|
1265
|
+
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);errorCategory=getErrorCategory(bsException,category);// send it to metrics service
|
|
1266
|
+
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,errorCategory),sendRawData:true},isRawResponse:true});}case 4:// Log handled errors and errors dispatched by the SDK
|
|
1263
1267
|
if(errorType===ErrorType.HANDLEDEXCEPTION||isSdkDispatched){this.logger.error(bsException.message);}_context.n=6;break;case 5:_context.p=5;_t=_context.v;// If an error occurs while handling an error, log it
|
|
1264
1268
|
this.logger.error(HANDLE_ERROR_FAILURE(ERROR_HANDLER),_t);case 6:return _context.a(2);}},_callee,this,[[0,5]]);}));function onError(_x){return _onError.apply(this,arguments);}return onError;}()/**
|
|
1265
1269
|
* Add breadcrumbs to add insight of a user's journey before an error
|
|
@@ -1345,7 +1349,7 @@ var userIdKey='rl_user_id';var userTraitsKey='rl_trait';var anonymousUserIdKey='
|
|
|
1345
1349
|
var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};
|
|
1346
1350
|
|
|
1347
1351
|
var EVENT_PAYLOAD_SIZE_BYTES_LIMIT=32*1024;// 32 KB
|
|
1348
|
-
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1352
|
+
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1349
1353
|
|
|
1350
1354
|
var isStorageQuotaExceeded=function isStorageQuotaExceeded(e){var matchingNames=['QuotaExceededError','NS_ERROR_DOM_QUOTA_REACHED'];// Everything except Firefox, Firefox
|
|
1351
1355
|
var matchingCodes=[22,1014];if(e instanceof DOMException){return matchingNames.includes(e.name)||matchingCodes.includes(e.code);}return false;};// TODO: also check for SecurityErrors
|
|
@@ -3299,7 +3303,8 @@ this.swapQueueStoreToInMemoryEngine();// and save it there
|
|
|
3299
3303
|
this.set(key,value);}else {var customMessage=STORE_DATA_SAVE_ERROR(key);this.onError(err,customMessage,customMessage);}}}/**
|
|
3300
3304
|
* Get by Key.
|
|
3301
3305
|
*/},{key:"get",value:function get(key){var validKey=this.createValidKey(key);var decryptedValue;try{if(!validKey){return null;}decryptedValue=this.decrypt(this.engine.getItem(validKey));if(isNullOrUndefined(decryptedValue)||decryptedValue===''){return null;}// storejs that is used in localstorage engine already deserializes json strings but swallows errors
|
|
3302
|
-
return JSON.parse(decryptedValue);}catch(err){var
|
|
3306
|
+
return JSON.parse(decryptedValue);}catch(err){var encryptionPluginName=state.storage.encryptionPluginName.value;// Skip error reporting only when the encryption plugin is configured but failed to load
|
|
3307
|
+
var shouldReportError=!encryptionPluginName||!state.plugins.failedPlugins.value.includes(encryptionPluginName);if(shouldReportError){var customMessage=STORE_DATA_FETCH_ERROR(key);this.onError(err,customMessage,customMessage);}return null;}}/**
|
|
3303
3308
|
* Remove by Key.
|
|
3304
3309
|
*/},{key:"remove",value:function remove(key){var validKey=this.createValidKey(key);if(validKey){this.engine.removeItem(validKey);}}/**
|
|
3305
3310
|
* Get original engine
|
|
@@ -3983,7 +3988,7 @@ E(function(){var areAllDestinationsReady=totalDestinationsToLoad===0||state.nati
|
|
|
3983
3988
|
*/// eslint-disable-next-line class-methods-use-this
|
|
3984
3989
|
},{key:"onDestinationsReady",value:function onDestinationsReady(){// May be do any destination specific actions here
|
|
3985
3990
|
// Mark the ready status if not already done
|
|
3986
|
-
if(state.lifecycle.status.value!=='ready'){state.lifecycle.status.value='ready';}}// End lifecycle methods
|
|
3991
|
+
if(state.lifecycle.status.value!=='ready'){r(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
3987
3992
|
// Start consumer exposed methods
|
|
3988
3993
|
},{key:"ready",value:function ready(callback){var type='ready';if(!state.lifecycle.loaded.value){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
3989
3994
|
* If destinations are loaded or no integration is available for loading
|
|
@@ -914,7 +914,7 @@
|
|
|
914
914
|
error.stacktrace="".concat(stacktrace,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case operaSourceloc:default:// eslint-disable-next-line no-param-reassign
|
|
915
915
|
error['opera#sourceloc']="".concat(operaSourceloc,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;}}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
916
916
|
|
|
917
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.
|
|
917
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.28.0';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
918
918
|
|
|
919
919
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
920
920
|
|
|
@@ -1137,7 +1137,7 @@
|
|
|
1137
1137
|
* Utility to parse XHR JSON response
|
|
1138
1138
|
*/var responseTextToJson=function responseTextToJson(responseText,onError){try{return JSON.parse(responseText||'');}catch(err){var error=getMutatedError(err,'Failed to parse response data');onError(error);}return undefined;};
|
|
1139
1139
|
|
|
1140
|
-
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);
|
|
1140
|
+
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);var INTEGRATIONS_ERROR_CATEGORY='integrations';var SDK_ERROR_CATEGORY='sdk';var DEFAULT_ERROR_CATEGORY=SDK_ERROR_CATEGORY;
|
|
1141
1141
|
|
|
1142
1142
|
var DEFAULT_XHR_REQUEST_OPTIONS={headers:{Accept:'application/json','Content-Type':'application/json;charset=UTF-8'},method:'GET'};/**
|
|
1143
1143
|
* Utility to create request configuration based on default options
|
|
@@ -1173,7 +1173,7 @@
|
|
|
1173
1173
|
// Potential PII or sensitive data
|
|
1174
1174
|
var APP_STATE_EXCLUDE_KEYS=['userId','userTraits','groupId','groupTraits','anonymousId','config','integration',// integration instance objects
|
|
1175
1175
|
'eventBuffer',// pre-load event buffer (may contain PII)
|
|
1176
|
-
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1176
|
+
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1177
1177
|
|
|
1178
1178
|
var detectAdBlockers=function detectAdBlockers(httpClient){state.capabilities.isAdBlockerDetectionInProgress.value=true;try{// Apparently, '?view=ad' is a query param that is blocked by majority of adblockers
|
|
1179
1179
|
// Use source config URL here as it is very unlikely to be blocked by adblockers
|
|
@@ -1217,23 +1217,27 @@
|
|
|
1217
1217
|
checkIfAdBlockersAreActive(state,httpClient,resolve);}}else {// Filter out errors that are not from the RS CDN.
|
|
1218
1218
|
resolve(false);}}else {// Allow the error to be notified if no URL could be extracted from the error message
|
|
1219
1219
|
resolve(true);}}else {resolve(!ERROR_MESSAGES_TO_BE_FILTERED.some(function(e){return e.test(errMsg);}));}});};/**
|
|
1220
|
+
* A function to get the directory name from a file path.
|
|
1221
|
+
* @param {string} filePath The file path
|
|
1222
|
+
* @returns The directory name or undefined if the file path is invalid
|
|
1223
|
+
*/var getDirectoryName=function getDirectoryName(filePath){if(!filePath){return undefined;}var paths=filePath.split('/');return paths.at(-2);};/**
|
|
1224
|
+
* A function to get the top stack path from the exception.
|
|
1225
|
+
* @param {Exception} exception The exception object
|
|
1226
|
+
* @returns The top stack path or undefined if the exception is invalid
|
|
1227
|
+
*/var getTopStackPath=function getTopStackPath(exception){var _exception$stacktrace;var errorOrigin=(_exception$stacktrace=exception.stacktrace[0])===null||_exception$stacktrace===void 0?void 0:_exception$stacktrace.file;if(!errorOrigin||typeof errorOrigin!=='string'){return undefined;}return errorOrigin;};/**
|
|
1220
1228
|
* A function to determine if the error is from Rudder SDK
|
|
1221
1229
|
* @param {Error} exception
|
|
1222
1230
|
* @returns
|
|
1223
|
-
*/var isSDKError=function isSDKError(exception){var
|
|
1224
|
-
// Ex: parentFolderName will be 'sample' for url: https://example.com/sample/file.min.js
|
|
1225
|
-
var parentFolderName=paths[paths.length-2];return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category!==null&&category!==void 0?category:DEFAULT_ERROR_CATEGORY},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1231
|
+
*/var isSDKError=function isSDKError(exception){var errorOrigin=getTopStackPath(exception);if(!errorOrigin){return false;}var srcFileName=errorOrigin.substring(errorOrigin.lastIndexOf('/')+1);var parentFolderName=getDirectoryName(errorOrigin);return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorCategory=function getErrorCategory(exception,category){if(category){return category;}var errorOrigin=getTopStackPath(exception);var directoryName=getDirectoryName(errorOrigin);if(directoryName===CDN_INT_DIR){return INTEGRATIONS_ERROR_CATEGORY;}return DEFAULT_ERROR_CATEGORY;};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1226
1232
|
* A function to get the grouping hash value to be used for the error event.
|
|
1227
|
-
* Grouping hash is suppressed for non-cdn installs.
|
|
1228
1233
|
* If the grouping hash is an error instance, the normalized error message is used as the grouping hash.
|
|
1229
1234
|
* If the grouping hash is an empty string or not specified, the default grouping hash is used.
|
|
1230
1235
|
* If the grouping hash is a string, it is used as is.
|
|
1231
1236
|
* @param curErrGroupingHash The grouping hash value part of the error event
|
|
1232
1237
|
* @param defaultGroupingHash The default grouping hash value. It is the error message.
|
|
1233
|
-
* @param state The application state
|
|
1234
1238
|
* @param logger The logger instance
|
|
1235
1239
|
* @returns The final grouping hash value to be used for the error event
|
|
1236
|
-
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,
|
|
1240
|
+
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,logger){var normalizedGroupingHash;if(!isDefined(curErrGroupingHash)){normalizedGroupingHash=defaultGroupingHash;}else if(isString(curErrGroupingHash)){normalizedGroupingHash=curErrGroupingHash;}else {var normalizedErrorInstance=normalizeError(curErrGroupingHash,logger);if(isDefined(normalizedErrorInstance)){normalizedGroupingHash=normalizedErrorInstance.message;}else {normalizedGroupingHash=defaultGroupingHash;}}return normalizedGroupingHash;};
|
|
1237
1241
|
|
|
1238
1242
|
/**
|
|
1239
1243
|
* A service to handle errors
|
|
@@ -1254,18 +1258,18 @@
|
|
|
1254
1258
|
* @param errorInfo.errorType - The type of the error (handled or unhandled)
|
|
1255
1259
|
* @param errorInfo.groupingHash - The grouping hash of the error
|
|
1256
1260
|
* @param errorInfo.category - The category of the error (sdk or integrations)
|
|
1257
|
-
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1261
|
+
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,errorCategory,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1258
1262
|
// In case of NPM installations, the unhandled errors from the SDK cannot be identified
|
|
1259
1263
|
// and will NOT be reported unless they occur in plugins or integrations.
|
|
1260
|
-
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};//
|
|
1261
|
-
//
|
|
1262
|
-
//
|
|
1264
|
+
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};// This will allow custom grouping of errors.
|
|
1265
|
+
// In case of NPM installations, the default grouping by surrounding code
|
|
1266
|
+
// does not make sense as each user application is different and will create a lot of noise in the alerts.
|
|
1263
1267
|
// References:
|
|
1264
1268
|
// https://docs.bugsnag.com/platforms/javascript/customizing-error-reports/#groupinghash
|
|
1265
1269
|
// https://docs.bugsnag.com/product/error-grouping/#user_defined
|
|
1266
|
-
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,
|
|
1267
|
-
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);// send it to metrics service
|
|
1268
|
-
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,
|
|
1270
|
+
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,this.logger);// Get the final payload to be sent to the metrics service
|
|
1271
|
+
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);errorCategory=getErrorCategory(bsException,category);// send it to metrics service
|
|
1272
|
+
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,errorCategory),sendRawData:true},isRawResponse:true});}case 4:// Log handled errors and errors dispatched by the SDK
|
|
1269
1273
|
if(errorType===ErrorType.HANDLEDEXCEPTION||isSdkDispatched){this.logger.error(bsException.message);}_context.n=6;break;case 5:_context.p=5;_t=_context.v;// If an error occurs while handling an error, log it
|
|
1270
1274
|
this.logger.error(HANDLE_ERROR_FAILURE(ERROR_HANDLER),_t);case 6:return _context.a(2);}},_callee,this,[[0,5]]);}));function onError(_x){return _onError.apply(this,arguments);}return onError;}()/**
|
|
1271
1275
|
* Add breadcrumbs to add insight of a user's journey before an error
|
|
@@ -1351,7 +1355,7 @@
|
|
|
1351
1355
|
var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};
|
|
1352
1356
|
|
|
1353
1357
|
var EVENT_PAYLOAD_SIZE_BYTES_LIMIT=32*1024;// 32 KB
|
|
1354
|
-
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1358
|
+
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1355
1359
|
|
|
1356
1360
|
var isStorageQuotaExceeded=function isStorageQuotaExceeded(e){var matchingNames=['QuotaExceededError','NS_ERROR_DOM_QUOTA_REACHED'];// Everything except Firefox, Firefox
|
|
1357
1361
|
var matchingCodes=[22,1014];if(e instanceof DOMException){return matchingNames.includes(e.name)||matchingCodes.includes(e.code);}return false;};// TODO: also check for SecurityErrors
|
|
@@ -3305,7 +3309,8 @@
|
|
|
3305
3309
|
this.set(key,value);}else {var customMessage=STORE_DATA_SAVE_ERROR(key);this.onError(err,customMessage,customMessage);}}}/**
|
|
3306
3310
|
* Get by Key.
|
|
3307
3311
|
*/},{key:"get",value:function get(key){var validKey=this.createValidKey(key);var decryptedValue;try{if(!validKey){return null;}decryptedValue=this.decrypt(this.engine.getItem(validKey));if(isNullOrUndefined(decryptedValue)||decryptedValue===''){return null;}// storejs that is used in localstorage engine already deserializes json strings but swallows errors
|
|
3308
|
-
return JSON.parse(decryptedValue);}catch(err){var
|
|
3312
|
+
return JSON.parse(decryptedValue);}catch(err){var encryptionPluginName=state.storage.encryptionPluginName.value;// Skip error reporting only when the encryption plugin is configured but failed to load
|
|
3313
|
+
var shouldReportError=!encryptionPluginName||!state.plugins.failedPlugins.value.includes(encryptionPluginName);if(shouldReportError){var customMessage=STORE_DATA_FETCH_ERROR(key);this.onError(err,customMessage,customMessage);}return null;}}/**
|
|
3309
3314
|
* Remove by Key.
|
|
3310
3315
|
*/},{key:"remove",value:function remove(key){var validKey=this.createValidKey(key);if(validKey){this.engine.removeItem(validKey);}}/**
|
|
3311
3316
|
* Get original engine
|
|
@@ -3989,7 +3994,7 @@
|
|
|
3989
3994
|
*/// eslint-disable-next-line class-methods-use-this
|
|
3990
3995
|
},{key:"onDestinationsReady",value:function onDestinationsReady(){// May be do any destination specific actions here
|
|
3991
3996
|
// Mark the ready status if not already done
|
|
3992
|
-
if(state.lifecycle.status.value!=='ready'){state.lifecycle.status.value='ready';}}// End lifecycle methods
|
|
3997
|
+
if(state.lifecycle.status.value!=='ready'){r(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
3993
3998
|
// Start consumer exposed methods
|
|
3994
3999
|
},{key:"ready",value:function ready(callback){var type='ready';if(!state.lifecycle.loaded.value){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
3995
4000
|
* If destinations are loaded or no integration is available for loading
|
|
@@ -908,7 +908,7 @@ error.stack="".concat(stack,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case sta
|
|
|
908
908
|
error.stacktrace="".concat(stacktrace,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;case operaSourceloc:default:// eslint-disable-next-line no-param-reassign
|
|
909
909
|
error['opera#sourceloc']="".concat(operaSourceloc,"\n").concat(MANUAL_ERROR_IDENTIFIER);break;}}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
910
910
|
|
|
911
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.
|
|
911
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.28.0';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
912
912
|
|
|
913
913
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
914
914
|
|
|
@@ -1131,7 +1131,7 @@ try{if(JSON.stringify(f)==='{}')return accum;return accum.concat(f);}catch(_unus
|
|
|
1131
1131
|
* Utility to parse XHR JSON response
|
|
1132
1132
|
*/var responseTextToJson=function responseTextToJson(responseText,onError){try{return JSON.parse(responseText||'');}catch(err){var error=getMutatedError(err,'Failed to parse response data');onError(error);}return undefined;};
|
|
1133
1133
|
|
|
1134
|
-
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);
|
|
1134
|
+
var FAILED_REQUEST_ERR_MSG_PREFIX='The request failed';var PLUGINS_LOAD_FAILURE_MESSAGES=[/Failed to fetch dynamically imported module: .*/];var INTEGRATIONS_LOAD_FAILURE_MESSAGES=[/Unable to load \(.*\) the script with the id .*/,/A timeout of \d+ ms occurred while trying to load the script with id .*/];var ERROR_MESSAGES_TO_BE_FILTERED=[new RegExp("".concat(FAILED_REQUEST_ERR_MSG_PREFIX,".*")),/A script with the id .* is already loaded\./];var SCRIPT_LOAD_FAILURE_MESSAGES=[].concat(PLUGINS_LOAD_FAILURE_MESSAGES,INTEGRATIONS_LOAD_FAILURE_MESSAGES);var INTEGRATIONS_ERROR_CATEGORY='integrations';var SDK_ERROR_CATEGORY='sdk';var DEFAULT_ERROR_CATEGORY=SDK_ERROR_CATEGORY;
|
|
1135
1135
|
|
|
1136
1136
|
var DEFAULT_XHR_REQUEST_OPTIONS={headers:{Accept:'application/json','Content-Type':'application/json;charset=UTF-8'},method:'GET'};/**
|
|
1137
1137
|
* Utility to create request configuration based on default options
|
|
@@ -1167,7 +1167,7 @@ var SDK_FILE_NAME_PREFIXES=function SDK_FILE_NAME_PREFIXES(){return ['rsa'// Pre
|
|
|
1167
1167
|
// Potential PII or sensitive data
|
|
1168
1168
|
var APP_STATE_EXCLUDE_KEYS=['userId','userTraits','groupId','groupTraits','anonymousId','config','integration',// integration instance objects
|
|
1169
1169
|
'eventBuffer',// pre-load event buffer (may contain PII)
|
|
1170
|
-
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1170
|
+
'traits','authToken'];var NOTIFIER_NAME='RudderStack JavaScript SDK';var SDK_GITHUB_URL='git+https://github.com/rudderlabs/rudder-sdk-js.git';var SOURCE_NAME='js';
|
|
1171
1171
|
|
|
1172
1172
|
var detectAdBlockers=function detectAdBlockers(httpClient){state.capabilities.isAdBlockerDetectionInProgress.value=true;try{// Apparently, '?view=ad' is a query param that is blocked by majority of adblockers
|
|
1173
1173
|
// Use source config URL here as it is very unlikely to be blocked by adblockers
|
|
@@ -1211,23 +1211,27 @@ if(state.capabilities.cspBlockedURLs.value.includes(extractedURL)){resolve(false
|
|
|
1211
1211
|
checkIfAdBlockersAreActive(state,httpClient,resolve);}}else {// Filter out errors that are not from the RS CDN.
|
|
1212
1212
|
resolve(false);}}else {// Allow the error to be notified if no URL could be extracted from the error message
|
|
1213
1213
|
resolve(true);}}else {resolve(!ERROR_MESSAGES_TO_BE_FILTERED.some(function(e){return e.test(errMsg);}));}});};/**
|
|
1214
|
+
* A function to get the directory name from a file path.
|
|
1215
|
+
* @param {string} filePath The file path
|
|
1216
|
+
* @returns The directory name or undefined if the file path is invalid
|
|
1217
|
+
*/var getDirectoryName=function getDirectoryName(filePath){if(!filePath){return undefined;}var paths=filePath.split('/');return paths.at(-2);};/**
|
|
1218
|
+
* A function to get the top stack path from the exception.
|
|
1219
|
+
* @param {Exception} exception The exception object
|
|
1220
|
+
* @returns The top stack path or undefined if the exception is invalid
|
|
1221
|
+
*/var getTopStackPath=function getTopStackPath(exception){var _exception$stacktrace;var errorOrigin=(_exception$stacktrace=exception.stacktrace[0])===null||_exception$stacktrace===void 0?void 0:_exception$stacktrace.file;if(!errorOrigin||typeof errorOrigin!=='string'){return undefined;}return errorOrigin;};/**
|
|
1214
1222
|
* A function to determine if the error is from Rudder SDK
|
|
1215
1223
|
* @param {Error} exception
|
|
1216
1224
|
* @returns
|
|
1217
|
-
*/var isSDKError=function isSDKError(exception){var
|
|
1218
|
-
// Ex: parentFolderName will be 'sample' for url: https://example.com/sample/file.min.js
|
|
1219
|
-
var parentFolderName=paths[paths.length-2];return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category!==null&&category!==void 0?category:DEFAULT_ERROR_CATEGORY},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1225
|
+
*/var isSDKError=function isSDKError(exception){var errorOrigin=getTopStackPath(exception);if(!errorOrigin){return false;}var srcFileName=errorOrigin.substring(errorOrigin.lastIndexOf('/')+1);var parentFolderName=getDirectoryName(errorOrigin);return parentFolderName===CDN_INT_DIR||SDK_FILE_NAME_PREFIXES().some(function(prefix){return srcFileName.startsWith(prefix)&&srcFileName.endsWith('.js');});};var getErrorCategory=function getErrorCategory(exception,category){if(category){return category;}var errorOrigin=getTopStackPath(exception);var directoryName=getDirectoryName(errorOrigin);if(directoryName===CDN_INT_DIR){return INTEGRATIONS_ERROR_CATEGORY;}return DEFAULT_ERROR_CATEGORY;};var getErrorDeliveryPayload=function getErrorDeliveryPayload(payload,state,category){var data={version:METRICS_PAYLOAD_VERSION,message_id:generateUUID(),source:{name:SOURCE_NAME,sdk_version:state.context.app.value.version,write_key:state.lifecycle.writeKey.value,install_type:state.context.app.value.installType,category:category},errors:payload};return stringifyWithoutCircular(data);};/**
|
|
1220
1226
|
* A function to get the grouping hash value to be used for the error event.
|
|
1221
|
-
* Grouping hash is suppressed for non-cdn installs.
|
|
1222
1227
|
* If the grouping hash is an error instance, the normalized error message is used as the grouping hash.
|
|
1223
1228
|
* If the grouping hash is an empty string or not specified, the default grouping hash is used.
|
|
1224
1229
|
* If the grouping hash is a string, it is used as is.
|
|
1225
1230
|
* @param curErrGroupingHash The grouping hash value part of the error event
|
|
1226
1231
|
* @param defaultGroupingHash The default grouping hash value. It is the error message.
|
|
1227
|
-
* @param state The application state
|
|
1228
1232
|
* @param logger The logger instance
|
|
1229
1233
|
* @returns The final grouping hash value to be used for the error event
|
|
1230
|
-
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,
|
|
1234
|
+
*/var getErrorGroupingHash=function getErrorGroupingHash(curErrGroupingHash,defaultGroupingHash,logger){var normalizedGroupingHash;if(!isDefined(curErrGroupingHash)){normalizedGroupingHash=defaultGroupingHash;}else if(isString(curErrGroupingHash)){normalizedGroupingHash=curErrGroupingHash;}else {var normalizedErrorInstance=normalizeError(curErrGroupingHash,logger);if(isDefined(normalizedErrorInstance)){normalizedGroupingHash=normalizedErrorInstance.message;}else {normalizedGroupingHash=defaultGroupingHash;}}return normalizedGroupingHash;};
|
|
1231
1235
|
|
|
1232
1236
|
/**
|
|
1233
1237
|
* A service to handle errors
|
|
@@ -1248,18 +1252,18 @@ document.addEventListener('securitypolicyviolation',function(event){var blockedU
|
|
|
1248
1252
|
* @param errorInfo.errorType - The type of the error (handled or unhandled)
|
|
1249
1253
|
* @param errorInfo.groupingHash - The grouping hash of the error
|
|
1250
1254
|
* @param errorInfo.category - The category of the error (sdk or integrations)
|
|
1251
|
-
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1255
|
+
*/},{key:"onError",value:(function(){var _onError=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(errorInfo){var _errorInfo$errorType,error,context,customMessage,groupingHash,category,errorType,errInstance,normalizedError,customMsgVal,errorMsgPrefix,bsException,stacktrace,isSdkDispatched,isAllowed,errorState,normalizedGroupingHash,bugsnagPayload,errorCategory,_t;return _regenerator().w(function(_context){while(1)switch(_context.p=_context.n){case 0:_context.p=0;error=errorInfo.error,context=errorInfo.context,customMessage=errorInfo.customMessage,groupingHash=errorInfo.groupingHash,category=errorInfo.category;errorType=(_errorInfo$errorType=errorInfo.errorType)!==null&&_errorInfo$errorType!==void 0?_errorInfo$errorType:ErrorType.HANDLEDEXCEPTION;errInstance=getErrInstance(error,errorType);normalizedError=normalizeError(errInstance,this.logger);if(!isUndefined(normalizedError)){_context.n=1;break;}return _context.a(2);case 1:customMsgVal=customMessage?"".concat(customMessage," - "):'';errorMsgPrefix="".concat(context).concat(LOG_CONTEXT_SEPARATOR).concat(customMsgVal);bsException=createBugsnagException(normalizedError,errorMsgPrefix);stacktrace=getStacktrace(normalizedError);isSdkDispatched=stacktrace.includes(MANUAL_ERROR_IDENTIFIER);// Filter errors that are not originated in the SDK.
|
|
1252
1256
|
// In case of NPM installations, the unhandled errors from the SDK cannot be identified
|
|
1253
1257
|
// and will NOT be reported unless they occur in plugins or integrations.
|
|
1254
|
-
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};//
|
|
1255
|
-
//
|
|
1256
|
-
//
|
|
1258
|
+
if(!(!isSdkDispatched&&!isSDKError(bsException)&&errorType!==ErrorType.HANDLEDEXCEPTION)){_context.n=2;break;}return _context.a(2);case 2:if(!state.reporting.isErrorReportingEnabled.value){_context.n=4;break;}_context.n=3;return checkIfAllowedToBeNotified(bsException,state,this.httpClient);case 3:isAllowed=_context.v;if(isAllowed){errorState={severity:'error',unhandled:errorType!==ErrorType.HANDLEDEXCEPTION,severityReason:{type:errorType}};// This will allow custom grouping of errors.
|
|
1259
|
+
// In case of NPM installations, the default grouping by surrounding code
|
|
1260
|
+
// does not make sense as each user application is different and will create a lot of noise in the alerts.
|
|
1257
1261
|
// References:
|
|
1258
1262
|
// https://docs.bugsnag.com/platforms/javascript/customizing-error-reports/#groupinghash
|
|
1259
1263
|
// https://docs.bugsnag.com/product/error-grouping/#user_defined
|
|
1260
|
-
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,
|
|
1261
|
-
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);// send it to metrics service
|
|
1262
|
-
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,
|
|
1264
|
+
normalizedGroupingHash=getErrorGroupingHash(groupingHash,bsException.message,this.logger);// Get the final payload to be sent to the metrics service
|
|
1265
|
+
bugsnagPayload=getBugsnagErrorEvent(bsException,errorState,state,normalizedGroupingHash);errorCategory=getErrorCategory(bsException,category);// send it to metrics service
|
|
1266
|
+
this.httpClient.getAsyncData({url:state.metrics.metricsServiceUrl.value,options:{method:'POST',data:getErrorDeliveryPayload(bugsnagPayload,state,errorCategory),sendRawData:true},isRawResponse:true});}case 4:// Log handled errors and errors dispatched by the SDK
|
|
1263
1267
|
if(errorType===ErrorType.HANDLEDEXCEPTION||isSdkDispatched){this.logger.error(bsException.message);}_context.n=6;break;case 5:_context.p=5;_t=_context.v;// If an error occurs while handling an error, log it
|
|
1264
1268
|
this.logger.error(HANDLE_ERROR_FAILURE(ERROR_HANDLER),_t);case 6:return _context.a(2);}},_callee,this,[[0,5]]);}));function onError(_x){return _onError.apply(this,arguments);}return onError;}()/**
|
|
1265
1269
|
* Add breadcrumbs to add insight of a user's journey before an error
|
|
@@ -1345,7 +1349,7 @@ var userIdKey='rl_user_id';var userTraitsKey='rl_trait';var anonymousUserIdKey='
|
|
|
1345
1349
|
var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};
|
|
1346
1350
|
|
|
1347
1351
|
var EVENT_PAYLOAD_SIZE_BYTES_LIMIT=32*1024;// 32 KB
|
|
1348
|
-
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1352
|
+
var RETRY_REASON_CLIENT_NETWORK='client-network';var RETRY_REASON_CLIENT_TIMEOUT='client-timeout';var DEFAULT_RETRY_REASON=RETRY_REASON_CLIENT_NETWORK;
|
|
1349
1353
|
|
|
1350
1354
|
var isStorageQuotaExceeded=function isStorageQuotaExceeded(e){var matchingNames=['QuotaExceededError','NS_ERROR_DOM_QUOTA_REACHED'];// Everything except Firefox, Firefox
|
|
1351
1355
|
var matchingCodes=[22,1014];if(e instanceof DOMException){return matchingNames.includes(e.name)||matchingCodes.includes(e.code);}return false;};// TODO: also check for SecurityErrors
|
|
@@ -3299,7 +3303,8 @@ this.swapQueueStoreToInMemoryEngine();// and save it there
|
|
|
3299
3303
|
this.set(key,value);}else {var customMessage=STORE_DATA_SAVE_ERROR(key);this.onError(err,customMessage,customMessage);}}}/**
|
|
3300
3304
|
* Get by Key.
|
|
3301
3305
|
*/},{key:"get",value:function get(key){var validKey=this.createValidKey(key);var decryptedValue;try{if(!validKey){return null;}decryptedValue=this.decrypt(this.engine.getItem(validKey));if(isNullOrUndefined(decryptedValue)||decryptedValue===''){return null;}// storejs that is used in localstorage engine already deserializes json strings but swallows errors
|
|
3302
|
-
return JSON.parse(decryptedValue);}catch(err){var
|
|
3306
|
+
return JSON.parse(decryptedValue);}catch(err){var encryptionPluginName=state.storage.encryptionPluginName.value;// Skip error reporting only when the encryption plugin is configured but failed to load
|
|
3307
|
+
var shouldReportError=!encryptionPluginName||!state.plugins.failedPlugins.value.includes(encryptionPluginName);if(shouldReportError){var customMessage=STORE_DATA_FETCH_ERROR(key);this.onError(err,customMessage,customMessage);}return null;}}/**
|
|
3303
3308
|
* Remove by Key.
|
|
3304
3309
|
*/},{key:"remove",value:function remove(key){var validKey=this.createValidKey(key);if(validKey){this.engine.removeItem(validKey);}}/**
|
|
3305
3310
|
* Get original engine
|
|
@@ -3983,7 +3988,7 @@ E(function(){var areAllDestinationsReady=totalDestinationsToLoad===0||state.nati
|
|
|
3983
3988
|
*/// eslint-disable-next-line class-methods-use-this
|
|
3984
3989
|
},{key:"onDestinationsReady",value:function onDestinationsReady(){// May be do any destination specific actions here
|
|
3985
3990
|
// Mark the ready status if not already done
|
|
3986
|
-
if(state.lifecycle.status.value!=='ready'){state.lifecycle.status.value='ready';}}// End lifecycle methods
|
|
3991
|
+
if(state.lifecycle.status.value!=='ready'){r(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
3987
3992
|
// Start consumer exposed methods
|
|
3988
3993
|
},{key:"ready",value:function ready(callback){var type='ready';if(!state.lifecycle.loaded.value){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
3989
3994
|
* If destinations are loaded or no integration is available for loading
|