Finding Third-Party Scripts That Worsen INP in Core Web Vitals
Third-party scripts loaded from external services, such as analytics tags and chat widgets, can also make Core Web Vitals INP (Interaction to Next Paint) worse. To find which script is responsible, look at the longestScript value from the attribution build of web-vitals. It shows the script's URL and how it was invoked. In a test environment, I added a tag that automatically records clicks to a page that only updates a cart count message when a button is pressed. INP went from 8ms to 256ms. This method is useful when PageSpeed Insights reports INP as "needs improvement" but you cannot find any heavy processing in your own code.
The test environment was Ubuntu 24.04, Node.js 22, and web-vitals 6.2.3. I used Chromium 153, bundled with Playwright 1.63.0, in headless mode, with a 412px × 823px viewport. The third-party scripts (tag.js and chat.js) are test code I wrote, not code from real services. Heavy processing is simulated with loops that keep the main thread busy for a set time. I did not connect to any external services. I used the example domains (www.example.com, tag.example.net, chat.example.org) and pointed them at a test server with Chrome's --host-resolver-rules. Each measurement was run twice, and unless noted otherwise, the values are from the first run. I did not test real tags or widgets, real user data (PageSpeed Insights field data), the Chrome DevTools Performance panel, CPU throttling, or browsers other than Chromium, such as Firefox or Safari.
- 1. Two ways third-party scripts make INP worse
- 2. The test page and how I measured
- 3. A tag that records clicks automatically increases processing duration
- 4. Calling the tag from your own listener makes your code look like the cause
- 5. A widget that runs periodically increases input delay
- 6. Load chat scripts only after the user presses the button
- 7. Summary of measured values
Two ways third-party scripts make INP worse
According to web.dev's explanation of INP, an INP of 200ms or less is "good," 500ms or less is "needs improvement," and anything slower is "poor." web.dev's guide to improving INP divides the time for one interaction into three parts: input delay (the time before event handling starts), processing duration (the time the event listeners run), and presentation delay (the time until the next frame is painted).
Third-party scripts add time in two of these parts:
- Processing duration: a tag attaches a click listener to
document, and that listener runs within the same event as your own listener every time the button is pressed. - Input delay: a widget runs heavy work on a
setIntervaltimer. If that work is running when the user presses the button, the handler has to wait until it finishes.
I reproduced both cases on a test page.
The test page and how I measured
The page has only a product name and an "add to cart" button. When the button is pressed, the page updates the item count.
<h1 style="font-size:22px">猫じゃらし(3本セット)</h1>
<button id="cart">カートに入れる</button>
<p id="status">カートは空です</p>
<script>
let count = 0;
const status = document.getElementById('status');
document.getElementById('cart').addEventListener('click', () => {
count++;
status.textContent = `カートに ${count} 個入っています`;
});
</script>
tag.js, which stands in for an analytics tag, is served from tag.example.net. Calling nekoTag.track() prepares one record to send and uses 250ms of processing time. If the <script> element that loads it has data-autoclick, the script attaches a listener to document that records every click on the page.
// Analytics tag stand-in, served from tag.example.net
(function () {
function busy(ms) {
const end = performance.now() + ms;
while (performance.now() < end) {}
}
// Prepare one record to send (stands in for inspecting page elements and building the payload; uses 250ms instead)
function record(name) {
busy(250);
}
window.nekoTag = { track: record };
// If data-autoclick is set, automatically record every click on the page
if (document.currentScript && document.currentScript.dataset.autoclick !== undefined) {
document.addEventListener('click', function (e) {
record('click');
});
}
})();
chat.js, which stands in for a chat widget, is served from chat.example.org. It adds an "Ask in chat" button at the bottom right of the screen and repeats 180ms of processing every 400ms.
// Chat widget stand-in, served from chat.example.org
(function () {
function busy(ms) {
const end = performance.now() + ms;
while (performance.now() < end) {}
}
const b = document.createElement('button');
b.textContent = 'チャットで質問';
b.style.cssText = 'position:fixed;right:16px;bottom:16px;font-size:16px;';
document.body.appendChild(b);
// Check for new messages and redraw the message bubbles (stands in for this; uses 180ms instead), repeated every 400ms
setInterval(function checkMessages() {
busy(180);
}, 400);
})();
For measurement, I used a Playwright script (measure.cjs) that opens the page and interacts with it. It waits one second after loading, then presses the cart button five times at 300ms intervals. After the last press, it dispatches a visibilitychange event, the same event that fires when a tab is switched, so that web-vitals finalizes the INP value. The script outputs the per-click durations collected with PerformanceObserver (Event Timing), the INP value from onINP in the attribution build of web-vitals, its breakdown, and longestScript.
I passed durationThreshold: 16 to onINP. According to the web-vitals README, by default it does not report interactions shorter than 40ms. I wanted to compare the shorter values after the fixes, so I lowered the threshold to 16ms. I also collected only Event Timing entries of 16ms or more. The README also says that the first interaction on a page always counts toward INP, regardless of its length. That is why an 8ms value can appear, since it is shorter than 16ms.
I ran all eight pages in a single command. The output below is from that run. On a page without any third-party scripts, INP was 8ms.
$ node measure.cjs none autoclick autoclick-sync track track-yield chat chat-facade chat-facade+open
browser: 153.0.8010.12
== none ==
status: カートに 5 個入っています
web-vitals onINP: 8ms rating=good (inputDelay 1, processingDuration 0, presentationDelay 7, target #cart)
longestScript: なし
…(続くページの出力は、以降の節に分けて載せます)
A tag that records clicks automatically increases processing duration
This page loads tag.js with data-autoclick. The script tag uses async.
<script async src="http://tag.example.net:8080/tag.js" data-autoclick></script>
== autoclick ==
click(16ms以上) 1 #cart: 256ms (delay 1, proc 250)
click(16ms以上) 2 #cart: 256ms (delay 1, proc 250)
click(16ms以上) 3 #cart: 256ms (delay 1, proc 250)
click(16ms以上) 4 #cart: 256ms (delay 1, proc 250)
click(16ms以上) 5 #cart: 256ms (delay 1, proc 250)
status: カートに 5 個入っています
web-vitals onINP: 256ms rating=needs-improvement (inputDelay 0, processingDuration 251, presentationDelay 5, target #cart)
longestScript: {"sourceURL":"http://tag.example.net:8080/tag.js","invoker":"#document.onclick","invokerType":"event-listener","subpart":"processing-duration","intersectingDuration":250}
My own listener only changes the displayed text, but each press added 250ms of processing duration. INP was 256ms, which is "needs improvement."
longestScript shows the cause right away. According to the web-vitals README, longestScript records the longest script that overlapped with the INP interaction. It contains the Long Animation Frames API entry (PerformanceScriptTiming) and the part of the interaction where the script ran (subpart). The values in this case are:
| Field | Value | How to read it |
|---|---|---|
sourceURL |
http://tag.example.net:8080/tag.js |
Which script ran |
invoker |
#document.onclick |
Called as a click listener on document |
invokerType |
event-listener |
An event listener |
subpart |
processing-duration |
Ran during processing duration |
intersectingDuration |
250 |
Time (ms) that overlapped with the INP interaction |
Chrome's explanation of the Long Animation Frames API says that sourceURL is the script's name, invoker is how it was called, and event-listener for invokerType means an event listener. The same explanation says that for a script from another origin that is loaded without CORS, only sourceURL is available, and function names and similar fields are empty. The sourceURL alone is enough to identify which service's script is responsible.
Removing async gave the same result:
== autoclick-sync ==
…
web-vitals onINP: 256ms rating=needs-improvement (inputDelay 0, processingDuration 251, presentationDelay 5, target #cart)
longestScript: {"sourceURL":"http://tag.example.net:8080/tag.js","invoker":"#document.onclick","invokerType":"event-listener","subpart":"processing-duration","intersectingDuration":250}
As MDN's explanation of the script element describes, async and defer only affect when a script is fetched and executed. A click listener that has already been attached runs on every click, whether or not async is set. For this kind of script, adding async did not improve INP.
Calling the tag from your own listener makes your code look like the cause
Next, I stopped the automatic recording and made the page call nekoTag.track() only from my own listener when an item is added to the cart.
document.getElementById('cart').addEventListener('click', () => {
count++;
status.textContent = `カートに ${count} 個入っています`;
window.nekoTag?.track('add_to_cart');
});
== track ==
click(16ms以上) 1 #cart: 256ms (delay 1, proc 250)
…
web-vitals onINP: 256ms rating=needs-improvement (inputDelay 0, processingDuration 251, presentationDelay 5, target #cart)
longestScript: {"sourceURL":"http://www.example.com:8080/track.html","invoker":"BUTTON#cart.onclick","invokerType":"event-listener","subpart":"processing-duration","intersectingDuration":250}
INP was the same 256ms. However, sourceURL now points to the page itself (track.html), and invoker is BUTTON#cart.onclick. The 250ms was spent inside tag.js, but the record does not show it.
The Long Animation Frames API records the script at the entry point where processing started. Chrome's explanation also says that when an event handler calls a library and a function in that library is slow, the record shows the event handler. Even when longestScript points to your own listener, a slow external function called from inside it may be the real cause.
In this case, you can change where the call happens. web.dev's guide to improving INP recommends that event listeners do only the work needed to update the next frame and defer everything else to a later task. I updated the display first, called scheduler.yield(), and then sent the record. As MDN's explanation of scheduler.yield() describes, scheduler.yield() gives up the main thread and continues the rest of the work in a later task.
document.getElementById('cart').addEventListener('click', async () => {
count++;
status.textContent = `カートに ${count} 個入っています`;
// Update the screen first, then send the record in a separate task afterward.
await scheduler.yield();
window.nekoTag?.track('add_to_cart');
});
== track-yield ==
status: カートに 5 個入っています
web-vitals onINP: 8ms rating=good (inputDelay 1, processingDuration 0, presentationDelay 7, target #cart)
longestScript: なし
INP returned to 8ms, and no click of 16ms or more was recorded. The recording work was not removed. It was moved to a separate task that runs after the display update.
A widget that runs periodically increases input delay
This page loads chat.js with async. The cart button listener is the same as on the first page.
== chat ==
click(16ms以上) 1 #cart: 32ms (delay 34, proc 0)
click(16ms以上) 2 #cart: 96ms (delay 97, proc 0)
click(16ms以上) 3 #cart: 96ms (delay 97, proc 0)
click(16ms以上) 4 #cart: 96ms (delay 96, proc 0)
status: カートに 5 個入っています
web-vitals onINP: 96ms rating=good (inputDelay 97, processingDuration 0, presentationDelay 0, target #cart)
longestScript: {"sourceURL":"http://chat.example.org:8080/chat.js","invoker":"TimerHandler:setInterval","invokerType":"user-callback","subpart":"input-delay","intersectingDuration":96}
The first line shows a duration (duration) shorter than the delay (delay). As the comment in the web-vitals code notes, Event Timing durations can be rounded down to 8ms steps.
Four of the five clicks were over 16ms, and in every case the extra time was input delay (delay). Processing duration (proc) was 0ms. This means the chat.js work was running when the button was pressed, so the listener could not start until that work finished. The wait depended on how far the timer work had progressed when the button was pressed. In this measurement, it ranged from 34 to 97ms. INP was 96ms. With this workload, that is in the "good" range. Still, it is much higher than the 8ms on the page without third-party scripts.
In longestScript, invoker is TimerHandler:setInterval, invokerType is user-callback, and subpart is input-delay. According to Chrome's explanation, user-callback means a callback registered with a Web API such as setTimeout. Combined with sourceURL, this reads as: "The click was delayed by work that a script from chat.example.org runs with setInterval."
web.dev's guide to reducing input delay explains that repeated work scheduled with setInterval often collides with user interactions. It also notes that you often cannot fix timers in third-party scripts yourself. In that case, it recommends checking with the stakeholders whether the script is really needed, and if it is, contacting the provider.
Load chat scripts only after the user presses the button
For something like a chat widget, which does nothing until someone uses it, you can follow the facade pattern described in Lighthouse's explanation of third-party facades. You place a lightweight stand-in element in the page, then load the real script when the user clicks it.
// Place a lightweight stand-in button instead of the real widget
const facade = document.createElement('button');
facade.id = 'chat-facade';
facade.textContent = 'チャットで質問';
facade.style.cssText = 'position:fixed;right:16px;bottom:16px;font-size:16px;';
facade.addEventListener('click', () => {
// Load the chat script only when the button is first pressed
facade.remove();
const s = document.createElement('script');
s.src = 'http://chat.example.org:8080/chat.js';
document.body.appendChild(s);
}, { once: true });
document.body.appendChild(facade);
== chat-facade ==
click(16ms以上) 1 #cart: 16ms (delay 1, proc 0)
status: カートに 5 個入っています
web-vitals onINP: 16ms rating=good (inputDelay 0, processingDuration 1, presentationDelay 15, target #cart)
longestScript: なし
When I pressed the cart button without pressing the chat button first, INP was 16ms. However, when I pressed the chat button to load chat.js and then pressed the cart button, the cart button was delayed in the same way as on the original page.
== chat-facade+open ==
チャットのボタンを押して、chat.js を読み込んだ
click(16ms以上) 1 #cart: 64ms (delay 59, proc 0)
click(16ms以上) 2 #cart: 96ms (delay 97, proc 0)
click(16ms以上) 3 #cart: 96ms (delay 97, proc 0)
click(16ms以上) 4 #cart: 96ms (delay 97, proc 0)
status: カートに 5 個入っています
web-vitals onINP: 96ms rating=good (inputDelay 97, processingDuration 0, presentationDelay 0, target #cart)
longestScript: {"sourceURL":"http://chat.example.org:8080/chat.js","invoker":"TimerHandler:setInterval","invokerType":"user-callback","subpart":"input-delay","intersectingDuration":96}
The facade only helps people who do not open the chat. To speed up interactions for people who do use the chat, the widget's own processing needs to become lighter.
Summary of measured values
These are the onINP values from the first run. The second run gave the same values on every page.

| Page | INP | sourceURL in longestScript |
Where the delay occurred |
|---|---|---|---|
| No third-party scripts | 8ms | none | none |
Automatic click recording tag (async) |
256ms | tag.js |
processing duration |
Automatic click recording tag (no async) |
256ms | tag.js |
processing duration |
track() called from own listener |
256ms | own page | processing duration |
Display updated, then scheduler.yield(), then track() |
8ms | none | none |
Chat widget (setInterval) |
96ms | chat.js |
input delay |
| Chat script loaded only after button press | 16ms | none | none |
| Same page, after chat script is loaded | 96ms | chat.js |
input delay |
If sourceURL in longestScript points to an external domain, that script was the longest one that overlapped with the INP interaction. If invokerType is event-listener, the script ran from a click or other event listener. If it is user-callback, the script ran from a timer or other callback. subpart tells you whether the script increased processing duration or input delay. If sourceURL points to your own page, also check whether that listener calls an external function. On this test page, moving the call to after the display update brought INP back to 8ms.





