Skip to content

Commit

Permalink
Merge branch 'main' of github.com:adobe/aem-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 committed Jun 28, 2024
2 parents 52f17c9 + 4cc1faa commit fd5f9e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<meta property="og:title" content="Page not found">
<script src="/scripts/scripts.js" type="module" crossorigin="use-credentials"></script>
<script type="module">
import { sampleRUM } from '/scripts/aem.js';

window.addEventListener('load', () => {
if (document.referrer) {
const { origin, pathname } = new URL(document.referrer);
Expand All @@ -26,9 +24,12 @@
btnContainer.append(backBtn);
}
}
sampleRUM('404', { source: document.referrer });
});
</script>
<script type="module">
import { sampleRUM } from '/scripts/aem.js';
sampleRUM('404', { source: document.referrer });
</script>
<link rel="stylesheet" href="/styles/styles.css">
<style>
main.error {
Expand Down
18 changes: 12 additions & 6 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ function init() {

window.addEventListener('load', () => sampleRUM('load'));

window.addEventListener('unhandledrejection', (event) => {
sampleRUM('error', { source: event.reason.sourceURL, target: event.reason.line });
});

window.addEventListener('error', (event) => {
sampleRUM('error', { source: event.filename, target: event.lineno });
['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);
});
});
}

Expand Down

0 comments on commit fd5f9e1

Please sign in to comment.