mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
support buffered option in PerformanceObserver.observe()
When buffered is true, deliver existing performance entries that match the observer's interest immediately, per the Performance Observer spec.
This commit is contained in:
@@ -69,3 +69,31 @@
|
|||||||
<script>
|
<script>
|
||||||
testing.expectEqual(['mark', 'measure'], PerformanceObserver.supportedEntryTypes);
|
testing.expectEqual(['mark', 'measure'], PerformanceObserver.supportedEntryTypes);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id="buffered_option">
|
||||||
|
{
|
||||||
|
// Create marks BEFORE the observer
|
||||||
|
performance.mark("early1", { startTime: 1.0 });
|
||||||
|
performance.mark("early2", { startTime: 2.0 });
|
||||||
|
|
||||||
|
let receivedEntries = null;
|
||||||
|
const observer = new PerformanceObserver((list) => {
|
||||||
|
receivedEntries = list.getEntries();
|
||||||
|
});
|
||||||
|
|
||||||
|
// With buffered: true, existing marks should be delivered immediately
|
||||||
|
observer.observe({ type: "mark", buffered: true });
|
||||||
|
|
||||||
|
testing.eventually(() => {
|
||||||
|
testing.expectEqual(true, receivedEntries !== null);
|
||||||
|
// Should have received at least the 2 early marks
|
||||||
|
testing.expectEqual(true, receivedEntries.length >= 2);
|
||||||
|
|
||||||
|
const names = receivedEntries.map(e => e.name);
|
||||||
|
testing.expectEqual(true, names.indexOf("early1") >= 0);
|
||||||
|
testing.expectEqual(true, names.indexOf("early2") >= 0);
|
||||||
|
|
||||||
|
observer.disconnect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -113,6 +113,18 @@ pub fn observe(
|
|||||||
|
|
||||||
// Update interests.
|
// Update interests.
|
||||||
self._interests = interests;
|
self._interests = interests;
|
||||||
|
|
||||||
|
// Deliver existing entries if buffered option is set.
|
||||||
|
if (options.buffered) {
|
||||||
|
for (page.window._performance._entries.items) |entry| {
|
||||||
|
if (self.interested(entry)) {
|
||||||
|
try self._entries.append(page.arena, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (self.hasRecords()) {
|
||||||
|
try self.dispatch(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disconnect(self: *PerformanceObserver, page: *Page) void {
|
pub fn disconnect(self: *PerformanceObserver, page: *Page) void {
|
||||||
|
|||||||
Reference in New Issue
Block a user