Skip to content

Commit 0da0ee4

Browse files
committed
Add sentry.io timings and context
Adds search results timing Adds more context (user and recent query information)
1 parent 7bbe553 commit 0da0ee4

File tree

9 files changed

+506
-365
lines changed

9 files changed

+506
-365
lines changed

src/config/common.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ define([], function () {
4444

4545
require([
4646
'config/discovery.vars',
47+
'config/utils',
4748
'regenerator-runtime',
4849
'array-flat-polyfill',
4950
'polyfill',
5051
'js/dark-mode-switch',
5152
], function (config) {
5253
// stub here to make sure these load before the main app
54+
5355
});
5456

5557
// set up handlebars helpers

src/config/utils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
define([], function() {
2+
3+
const DEFAULT_TIMEOUT = 30000;
4+
5+
/**
6+
* Waits for an element to appear in the DOM and be interactive using MutationObserver.
7+
* @param {string} selector - The CSS selector of the element to wait for.
8+
* @param {number} timeout - The maximum time to wait in milliseconds (default is 5000ms).
9+
* @returns {Promise<Element>} - A promise that resolves to the found element.
10+
*/
11+
function waitForElement(selector, timeout = DEFAULT_TIMEOUT) {
12+
return new Promise((resolve, reject) => {
13+
const observer = new MutationObserver(() => {
14+
const element = document.querySelector(selector);
15+
16+
if (element && element.offsetParent !== null) {
17+
observer.disconnect(); // Stop observing once the element is found and interactive
18+
resolve(element);
19+
}
20+
});
21+
22+
// Start observing the document for changes in the DOM
23+
observer.observe(document.body, { childList: true, subtree: true });
24+
25+
// Set a timeout to stop observing if the element doesn't appear in time
26+
setTimeout(() => {
27+
observer.disconnect();
28+
reject(
29+
new Error(
30+
`Element with selector "${selector}" was not found within ${timeout}ms.`
31+
)
32+
);
33+
}, timeout);
34+
});
35+
}
36+
37+
window.utils = {
38+
waitForElement: waitForElement,
39+
};
40+
41+
return window.utils;
42+
});

0 commit comments

Comments
 (0)