In short
The Long Animation Frames (LoAF) API reports every frame the browser took more than 50 milliseconds to produce, and names the scripts that delayed it: file, function, invoker type, duration. Tied to INP (Interaction to Next Paint, the delay between a visitor's action and the next paint), it tells you not only which interaction is slow, but which code is responsible. Once this check is done, you have a ranking of the offending scripts, measured on real visitors.
Why it matters
Chrome's field data (CrUX) tells you that a page has a poor INP, not why. The Performance panel in DevTools shows the cause, but only on your machine, with your own path through the page, without the consent banner or the tags that visitors receive. Between the two, attribution is missing: which script was running when the interaction was slow.
The older Long Tasks API reported tasks longer than 50 ms while saying almost nothing about where they came from. LoAF works frame by frame, which is closer to what INP measures, and details every script of at least 5 ms. A long-animation-frame entry contains, among other things:
| Field | What it tells you |
|---|---|
duration |
Total duration of the long frame |
blockingDuration |
Time during which the main thread could not have handled an interaction |
renderStart, styleAndLayoutStart |
Start of rendering, then of style and layout calculation |
firstUIEventTimestamp |
First interaction handled during the frame |
scripts |
Array of the scripts that contributed |
And each item in scripts:
| Field | What it tells you |
|---|---|
sourceURL |
File the script comes from |
sourceFunctionName, sourceCharPosition |
Function and position in the file |
invoker |
What called it: BUTTON#acheter.onclick, Window.requestAnimationFrame, script URL |
invokerType |
event-listener, user-callback, classic-script, module-script, resolve-promise, reject-promise |
duration |
Execution time |
forcedStyleAndLayoutDuration |
Time spent on layout recalculations forced by the script |
pauseDuration |
Time spent in a blocking operation (alert, synchronous request) |
Limitations to be aware of. The API only exists in Chromium browsers (Chrome and Edge 123 and later); Firefox and Safari do not offer it, according to the Chrome documentation. Scripts in a cross-origin iframe, in workers and in extensions are not attributed. A third-party script loaded without CORS only exposes its sourceURL. Lastly, it is the entry point that is reported, not necessarily the slowest function inside it.
What it improves
- INP diagnosis You move from “this page is slow” to “this file, called by this click, blocked for this many milliseconds”. It is the prerequisite for the work described in target an INP of 200 ms (opens in a new tab).
- Decisions about third-party scripts Measured durations per vendor, to decide what to remove, defer or renegotiate.
- Development time Fixes target the scripts that are actually responsible, not guesses.
- Rankings No direct effect. Measuring changes nothing; only the fixes improve INP, itself one signal among many others.
- Coverage Partial. Visitors on Safari and Firefox do not report any LoAF data.
How to check
First check that your browser exposes the API, in the console:
PerformanceObserver.supportedEntryTypes.includes('long-animation-frame');
Then see whether the site already collects this data: in the Network tab, filter on the collection endpoint (/rum, collect, matomo.php), interact with the page, then switch tabs. Compliant result: a request is sent with the INP value, the targeted element and at least one sourceURL.
With no collection in place, the question you need to be able to answer is simple: on your pages with a poor INP, which script weighs the most? If the answer is “we don't know”, the check remains to be done. Find those pages with real-user CrUX data (opens in a new tab).
How to implement
Step 1 — Observe long frames locally
Paste this code into the console, then use the page (menu, filters, consent banner):
const observateur = new PerformanceObserver((liste) => {
for (const image of liste.getEntries()) {
console.table(image.scripts.map((script) => ({
fichier: script.sourceURL,
fonction: script.sourceFunctionName,
appelant: script.invoker,
type: script.invokerType,
duree: Math.round(script.duration),
miseEnPageForcee: Math.round(script.forcedStyleAndLayoutDuration),
})));
}
});
observateur.observe({ type: 'long-animation-frame', buffered: true });
Use a PerformanceObserver rather than performance.getEntriesByType(): the buffer is limited to 200 entries, and any after that are lost.
Step 2 — Tie long frames to INP
No API directly links an interaction to its long frames. The web-vitals library, in its “attribution” build, does the matching. Install it and host it yourself, which its authors recommend over a public CDN:
npm install web-vitals
import { onINP } from 'web-vitals/attribution';
function origine(url) {
if (! url) {
return 'inconnue';
}
return new URL(url, location.href).hostname === location.hostname ? 'interne' : 'tiers';
}
onINP(({ value, rating, attribution }) => {
const script = attribution.longestScript?.entry;
envoyer({
page: location.pathname,
inp: Math.round(value),
note: rating,
cible: attribution.interactionTarget,
etatChargement: attribution.loadState,
delaiEntree: Math.round(attribution.inputDelay),
traitement: Math.round(attribution.processingDuration),
presentation: Math.round(attribution.presentationDelay),
phaseDuScript: attribution.longestScript?.subpart,
fichier: script?.sourceURL ?? '',
fonction: script?.sourceFunctionName ?? '',
appelant: script?.invoker ?? '',
typeAppel: script?.invokerType ?? '',
origine: origine(script?.sourceURL),
dureeScripts: Math.round(attribution.totalScriptDuration ?? 0),
dureeMiseEnPage: Math.round(attribution.totalStyleAndLayoutDuration ?? 0),
});
});
attribution.longAnimationFrameEntries contains the raw entries if you want every script and not just the longest one. These fields are the ones documented for versions 5 and 6 of the library; re-read its README at every major version upgrade. In browsers without LoAF, the script-related fields are simply absent.
Good to know: to get the function and position of a third-party script, and not just its
sourceURL, load it with thecrossorigin="anonymous"attribute, provided its server sends the CORS headers.
Step 3 — Send the measurements
There are three possible destinations for the envoyer function. The first is free and has no dependency.
Self-hosted collection endpoint
function envoyer(mesure) {
navigator.sendBeacon('/rum', JSON.stringify(mesure));
}
Store one row per measurement (log file, SQL table). Keep neither IP address nor identifier: the page path and the fields above are enough.
function envoyer(mesure) {
gtag('event', 'INP', {
value: mesure.inp,
metric_rating: mesure.note,
debug_target: mesure.cible,
debug_script: mesure.fichier,
debug_invoker: mesure.appelant,
debug_origin: mesure.origine,
});
}
These parameters only appear in reports once they have been registered as custom dimensions in the property's admin settings; the BigQuery export contains them without any registration. The parameter names are up to you.
function envoyer(mesure) {
_paq.push(['trackEvent', 'INP', mesure.note, `${mesure.origine} ${mesure.fichier}`, mesure.inp]);
}
In both cases, sending follows the same rules as the rest of your analytics: see handle applicable consent requirements (opens in a new tab). If you already use a real user monitoring service (SpeedCurve, DebugBear…), check in its documentation whether it already collects LoAF before adding your own code.
Step 4 — Read the results
Wait until you have enough measurements per template, then build this table from the interactions whose INP exceeds 200 ms:
| Column | Content |
|---|---|
| Template | Page type (product page, listing, article) |
| Target | Element of the interaction (cible) |
| File | sourceURL of the longest script, grouped by file name without parameters |
| Origin | Internal or third-party |
| Occurrences | Number of slow interactions concerned |
| Median duration | Median of the script duration |
Sort by occurrences. The invoker type and the phase then point you to the fix:
| Finding | Interpretation | Lead |
|---|---|---|
input-delay phase, classic-script or module-script type, during loading |
A script is being evaluated just as the visitor acts | Defer non-essential scripts (opens in a new tab) |
input-delay phase, user-callback type |
Timer or requestAnimationFrame in progress |
Break up the task, space out the timers |
processing-duration phase, event-listener type |
The event handler itself is heavy | Do the minimum, postpone the rest |
High dureeMiseEnPage |
Style and layout recalculations | Reduce DOM complexity (opens in a new tab) |
| Third-party origin dominant | Marketing tag, live chat, A/B test | Limit third-party scripts (opens in a new tab) |
Step 5 — Reproduce in DevTools
Open Chrome's Performance panel. The landing view shows live INP and the Interactions log; set CPU throttling in the environment settings. Record the interaction identified in step 4, then:
- the
Interactionstrack shows the interaction and its three phases, with a red triangle beyond 200 ms; - the
Maintrack marks long tasks with a red triangle; click to find the file and function given bysourceURL; - the
Dim 3rd partiescheckbox grays out third-party code; with nothing selected, theSummarytab displays a1st / 3rd partytable with main-thread time per entity.
The Chrome documentation also describes how to display your LoAF entries in a custom track with performance.measure().
WordPress
Versions WordPress 6.5 and later (script modules).
Copy the file from step 2, bundled with the library, into the child theme, then load it as a module:
add_action('wp_enqueue_scripts', function (): void {
wp_enqueue_script_module(
'inp-loaf',
get_stylesheet_directory_uri() . '/js/inp-loaf.js',
[],
'1.0.0'
);
});
In the results, the path in sourceURL points to the culprit: /wp-content/plugins/{plugin}/ or /wp-content/themes/{theme}/. If an optimization plugin concatenates JavaScript files, every script carries the same sourceURL: turn concatenation off during the measurement period.
Next.js
Versions Next.js 15 and 16 (App Router).
The useReportWebVitals hook provides the INP value, but its documentation does not mention attribution. Load the library yourself in a client component, imported into the root layout:
'use client';
import { useEffect } from 'react';
export function InpDiagnostics() {
useEffect(() => {
import('web-vitals/attribution').then(({ onINP }) => {
onINP(({ value, attribution }) => {
navigator.sendBeacon('/api/rum', JSON.stringify({
page: location.pathname,
inp: Math.round(value),
cible: attribution.interactionTarget,
fichier: attribution.longestScript?.entry.sourceURL ?? '',
}));
});
});
}, []);
return null;
}
Files have generated chunk names (/_next/static/chunks/…): use sourceFunctionName and source maps to trace them back to the component.
Laravel
Versions Laravel 11 to 13.
Receive the measurements in a dedicated controller and write them to a log channel:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;
class RumReportsController extends Controller
{
public function store(Request $request): Response
{
$report = json_decode($request->getContent(), true);
if (! is_array($report)) {
return response()->noContent();
}
Log::channel('rum')->info('inp', $report);
return response()->noContent();
}
}
Route::post('/rum', [RumReportsController::class, 'store'])->name('rumReports.store');
navigator.sendBeacon does not send a CSRF token: exempt this route from verification, as described in the CSRF documentation for your version, and rate-limit it with the throttle middleware. Declare the rum channel in config/logging.php.
Common mistakes
- Sending every long frame: the volume explodes. Send only those tied to INP, which is what the library does.
- Mistaking the entry point for the culprit: a tag manager shows up as the
sourceURLof everything it loads. Look at what it triggers. - Drawing conclusions from Chrome alone: there is no LoAF data for Safari and Firefox, where INP may have other causes.
- Forgetting cross-origin iframes: ads and video players in an iframe do not appear in
scripts, even though they can slow the device down. - Grouping by full URL: version parameters and hashes scatter the results. Group by domain and file name.
- Measuring without fixing: the collection itself adds a script. Remove it or sample it once the diagnosis is made.
Frequently asked questions
What is the difference between Long Tasks and Long Animation Frames?
The Long Tasks API reports tasks longer than 50 milliseconds on the main thread, while saying almost nothing about where they come from. Long Animation Frames measures the time needed to produce a frame, grouping the tasks and the rendering that delay it, and provides the file, function, invoker type and duration for each script. It is therefore closer to what INP measures.
Does the Long Animation Frames API work in Safari and Firefox?
No, according to the Chrome documentation: the Long Animation Frames API has been available in Chrome and Edge since version 123, but not in Firefox or Safari. Test for it with PerformanceObserver.supportedEntryTypes before using it. The web-vitals library measures INP in all three browsers, but script attribution is only filled in where the API exists. Check the current status in the MDN compatibility table.
How do I find out which third-party script is hurting INP?
Collect INP with the attribution build of the web-vitals library and record the sourceURL field of the longest script for each slow interaction. Compare its domain name with the site's to classify it as internal or third-party, then count the occurrences per domain. Scripts placed in a cross-origin iframe are not covered by this measurement.
Does measuring INP with LoAF slow the site down?
Very little, as long as the collection stays lean. The browser produces Long Animation Frames entries anyway; the cost comes from the collection script and from sending the data. Load the library as a deferred module, send only one measurement per page when it goes to the background, and sample visits if traffic is high. Remove the code once the diagnosis is complete.
Resources
- Chrome for Developers: Long Animation Frames APIdeveloper.chrome.com
- web.dev: Find slow interactions in the fieldweb.dev
- web-vitals library: README and INPAttribution interfacegithub.com
- MDN: PerformanceLongAnimationFrameTimingdeveloper.mozilla.org
- Chrome DevTools: Performance panel referencedeveloper.chrome.com
- Next.js: useReportWebVitalsnextjs.org
- Laravel: CSRF protectionlaravel.com
Updated on
Topic checklist (PDF)