Skip to content

Commit

Permalink
fix(lib): update scripts/aem.js to aem.js@2.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot committed Aug 13, 2024
1 parent d01adf4 commit 85fa94e
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,39 @@ function sampleRUM(checkpoint, data) {
collector: (...args) => window.hlx.rum.queue.push(args),
};
if (isSelected) {
['error', 'unhandledrejection'].forEach((event) => {
window.addEventListener(event, ({ reason, error }) => {
const errData = { source: 'undefined error' };
try {
errData.target = (reason || error).toString();
errData.source = (reason || error).stack
.split('\n')
.filter((line) => line.match(/https?:\/\//))
.shift()
.replace(/at ([^ ]+) \((.+)\)/, '$1@$2')
.trim();
} catch (err) {
/* error structure was not as expected */
}
sampleRUM('error', errData);
});
const dataFromErrorObj = (error) => {
const errData = { source: 'undefined error' };
try {
errData.target = error.toString();
errData.source = error.stack
.split('\n')
.filter((line) => line.match(/https?:\/\//))
.shift()
.replace(/at ([^ ]+) \((.+)\)/, '$1@$2')
.replace(/ at /, '@')
.trim();
} catch (err) {
/* error structure was not as expected */
}
return errData;
};

window.addEventListener('error', ({ error }) => {
const errData = dataFromErrorObj(error);
sampleRUM('error', errData);
});

window.addEventListener('unhandledrejection', ({ reason }) => {
let errData = {
source: 'Unhandled Rejection',
target: reason || 'Unknown',
};
if (reason instanceof Error) {
errData = dataFromErrorObj(reason);
}
sampleRUM('error', errData);
});

sampleRUM.baseURL = sampleRUM.baseURL || new URL(window.RUM_BASE || '/', new URL('https://rum.hlx.page'));
sampleRUM.collectBaseURL = sampleRUM.collectBaseURL || sampleRUM.baseURL;
sampleRUM.sendPing = (ck, time, pingData = {}) => {
Expand Down

0 comments on commit 85fa94e

Please sign in to comment.