Skip to content

Commit 386fb3e

Browse files
committed
Add INP test interactions with heavy computation, DOM manipulation, and layout shift features
1 parent aa18c07 commit 386fb3e

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

examples/BasicRUM.html

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,39 @@ <h1 class="text-center">Raygun4JS - Basic Example</h1>
3535
Throw an error
3636
</a>
3737
</p>
38+
39+
<div class="row" style="margin-top: 30px;">
40+
<div class="col-md-6">
41+
<h3>INP Test Interactions</h3>
42+
<div class="panel panel-default">
43+
<div class="panel-body">
44+
<button class="btn btn-primary btn-block" id="HeavyComputeButton">
45+
Heavy Computation (100ms delay)
46+
</button>
47+
<br>
48+
<button class="btn btn-info btn-block" id="DOMManipulationButton">
49+
DOM Manipulation
50+
</button>
51+
<br>
52+
<input type="text" class="form-control" id="DelayedInput" placeholder="Type here (delayed response)">
53+
<br>
54+
<button class="btn btn-warning btn-block" id="LayoutShiftButton">
55+
Trigger Layout Shift
56+
</button>
57+
</div>
58+
</div>
59+
</div>
60+
<div class="col-md-6">
61+
<h3>Results</h3>
62+
<div class="panel panel-default">
63+
<div class="panel-body">
64+
<div id="InteractionResults" style="min-height: 200px; background-color: #f9f9f9; padding: 10px; border-radius: 4px;">
65+
<em>Interaction results will appear here...</em>
66+
</div>
67+
</div>
68+
</div>
69+
</div>
70+
</div>
3871
</div>
3972
</div>
4073

@@ -47,9 +80,98 @@ <h1 class="text-center">Raygun4JS - Basic Example</h1>
4780

4881
<script type="text/javascript">
4982
$(function () {
83+
let interactionCount = 0;
84+
const resultsDiv = $('#InteractionResults');
85+
86+
function addResult(message) {
87+
interactionCount++;
88+
const timestamp = new Date().toLocaleTimeString();
89+
resultsDiv.append(`<div><strong>${interactionCount}.</strong> [${timestamp}] ${message}</div>`);
90+
resultsDiv.scrollTop(resultsDiv[0].scrollHeight);
91+
}
92+
93+
// Original error button
5094
$('#ErrorButton').click(function () {
95+
addResult('Error thrown - check Raygun dashboard');
5196
bob.GetMessage();
5297
});
98+
99+
// Heavy computation button (simulates CPU-intensive work)
100+
$('#HeavyComputeButton').click(function () {
101+
addResult('Starting heavy computation...');
102+
103+
// Simulate heavy computation with a blocking operation
104+
const start = performance.now();
105+
const duration = 100; // 100ms delay
106+
107+
// CPU-intensive loop
108+
let result = 0;
109+
while (performance.now() - start < duration) {
110+
result += Math.random() * Math.random();
111+
}
112+
113+
addResult(`Heavy computation completed (${(performance.now() - start).toFixed(2)}ms)`);
114+
});
115+
116+
// DOM manipulation button
117+
$('#DOMManipulationButton').click(function () {
118+
addResult('Performing DOM manipulation...');
119+
120+
// Create and remove many DOM elements
121+
const container = $('<div>').appendTo('body');
122+
for (let i = 0; i < 100; i++) {
123+
const element = $(`<div class="test-element" style="position: absolute; left: ${Math.random() * 100}px; top: ${Math.random() * 100}px; width: 10px; height: 10px; background: red;"></div>`);
124+
container.append(element);
125+
}
126+
127+
// Force layout recalculation
128+
container[0].offsetHeight;
129+
130+
// Remove elements after a short delay
131+
setTimeout(() => {
132+
container.remove();
133+
addResult('DOM manipulation completed');
134+
}, 50);
135+
});
136+
137+
// Delayed input response
138+
let inputTimeout;
139+
$('#DelayedInput').on('input', function () {
140+
const value = $(this).val();
141+
clearTimeout(inputTimeout);
142+
143+
addResult(`Input detected: "${value}"`);
144+
145+
// Simulate delayed processing
146+
inputTimeout = setTimeout(() => {
147+
// Simulate heavy processing on input
148+
let result = 0;
149+
for (let i = 0; i < 100000; i++) {
150+
result += Math.sin(i) * Math.cos(i);
151+
}
152+
addResult(`Input processing completed for: "${value}"`);
153+
}, 50);
154+
});
155+
156+
// Layout shift button
157+
$('#LayoutShiftButton').click(function () {
158+
addResult('Triggering layout shift...');
159+
160+
// Create a large element that causes layout shift
161+
const shiftElement = $(`<div style="height: 200px; background: linear-gradient(45deg, #ff6b6b, #4ecdc4); margin: 20px 0; padding: 20px; border-radius: 8px; color: white; text-align: center; line-height: 160px; font-size: 18px; font-weight: bold;">Layout Shift Element</div>`);
162+
163+
// Insert before the results panel to cause layout shift
164+
$('.row').before(shiftElement);
165+
166+
// Remove after 2 seconds
167+
setTimeout(() => {
168+
shiftElement.remove();
169+
addResult('Layout shift element removed');
170+
}, 2000);
171+
});
172+
173+
// Initialize
174+
addResult('INP test interactions ready. Try clicking buttons and typing in the input field.');
53175
});
54176
</script>
55177

0 commit comments

Comments
 (0)