Fixing Lighthouse “Uses deprecated APIs” Warnings
When Lighthouse's Best Practices category shows "Uses deprecated APIs" (the Japanese UI shows it as a label meaning "Deprecated APIs are used"), replace each API listed in the table with the alternative given in its message. This audit usually shows up on sites that still run old JavaScript, or on pages that use synchronous XMLHttpRequest or the unload event.
I put five deprecated patterns into a test page. After fixing each one, I ran Lighthouse and checked which entries disappeared from the table and which remained. To confirm that the page still behaved the same, I opened it in Playwright.
The test environment was Ubuntu 24.04, Node.js 22, and Lighthouse 13.6.0 (the npm package). I ran Lighthouse from the command line with the default settings (mobile), and only the Best Practices category. For Chrome, I used Chrome for Testing 153, which comes with Playwright 1.63.0. I passed that Chrome to Lighthouse through the CHROME_PATH environment variable. The server was a small one I wrote with Node.js's http module, running on localhost on the same machine. I did not test the Lighthouse panel in DevTools, PageSpeed Insights, warnings from third-party scripts, or any APIs other than the five covered here.
- 1. Lighthouse lists the warnings that Chrome emits
- 2. Use srcset for source inside picture
- 3. Replace synchronous XMLHttpRequest with fetch
- 4. Replace unload with pagehide
- 5. The same kind of warning moves to the next place when you fix one
- 6. Replace createEvent and initKeyboardEvent with the KeyboardEvent constructor
Lighthouse lists the warnings that Chrome emits
According to the official explanation, this audit collects every deprecation warning that Chrome prints to the DevTools console. Chrome decides which APIs are covered. Lighthouse does not keep its own list.
The test page is a small one made only of HTML and JavaScript (app.js). In the HTML, I put a src attribute on a <source> inside <picture>.
<picture>
<source src="/hero.webp" type="image/webp">
<img src="/hero.png" alt="お知らせの見出しの画像" width="320" height="160">
</picture>
app.js looks like this:
// Load the news with a synchronous XMLHttpRequest
const xhr = new XMLHttpRequest();
xhr.open('GET', '/api/news.json', false);
xhr.send();
document.querySelector('#news').textContent = JSON.parse(xhr.responseText)[0].title;
// Send a view log when the page is left
window.addEventListener('unload', () => {
navigator.sendBeacon('/api/log', 'leave');
});
// Fade in the heading little by little
let opacity = 0;
function fadeIn() {
opacity += 0.1;
document.querySelector('h1').style.opacity = String(opacity);
if (opacity < 1) window.webkitRequestAnimationFrame(fadeIn);
}
window.webkitRequestAnimationFrame(fadeIn);
// Pretend the Escape key was pressed (for testing)
document.addEventListener('keydown', (e) => console.log(`keydown: ${e.key}`));
const ev = document.createEvent('KeyboardEvents');
ev.initKeyboardEvent('keydown', true, true, window, 'Escape');
document.dispatchEvent(ev);
I ran Lighthouse on this page, then used a small script (summarize.mjs) to pull the results for this audit (deprecations) out of the JSON output. The row and column values match what the HTML report shows.
$ npx lighthouse http://localhost:8100/ --only-categories=best-practices --output=json --output=html --output-path=./out/broken --chrome-flags="--headless=new --no-sandbox" --quiet
exit: 0
$ node summarize.mjs out/broken.report.json
lighthouseVersion: 13.6.0 formFactor: mobile locale: en-US
best-practices score: 81
deprecations: score=0 title="Uses deprecated APIs" displayValue="5 warnings found"
item: source=/:14:0 value="<source src> with a <picture> parent is invalid and therefore ignored. Please use <source srcset> instead."
item: source=/app.js:3:5 value="Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/."
item: source=/app.js:8:8 value="Unload event listeners are deprecated and will be removed."
link: Check the feature status page for more details. https://chromestatus.com/feature/5579556305502208
item: source=/app.js:19:8 value="webkitRequestAnimationFrame is vendor-specific. Please use the standard requestAnimationFrame instead."
item: source=/app.js:23:21 value="document.createEvent('KeyboardEvents') is deprecated and will be removed. Use new KeyboardEvent() instead."
link: Check the feature status page for more details. https://chromestatus.com/feature/5095987863486464
link: This change will go into effect with milestone 151. https://chromiumdash.appspot.com/schedule
weight in best-practices: 5
In the HTML report, this audit appears as an item with a red triangle icon. When you expand it, a table appears with the warning text (Deprecation / Warning) and the location where it occurred (Source).

The warning text usually says what to use instead. When I ran the audit with --locale=ja, the messages came out in Japanese. For example, the unload row said that unload event listeners are no longer supported and will be removed.
The audit's weight in Best Practices is 5, and the total weight is 26. In the Lighthouse 13.6.0 code, this audit scores 0 if there is at least one warning, regardless of the count, and full marks if there are none. All other audits passed, so the score stayed at 81 (21 ÷ 26) whether there were 5 warnings or 1. It only became 100 when there were none.
Use srcset for source inside picture
The first Source entry points to /:14:0, which is line 14 of the HTML. Counting from the <!doctype html> at the top, the <source> I wrote is on line 13. The line Lighthouse pointed to was the <img> on the next line.
MDN's explanation of the source element says that when the parent is <picture>, src cannot be used and srcset is required. As the warning says, the <source> with src is ignored. In the request log before the fix, the browser loaded /hero.png, and the WebP image was never used.
- <source src="/hero.webp" type="image/webp">
+ <source srcset="/hero.webp" type="image/webp">
After the fix, the browser loaded /hero.webp, and the first row disappeared from the table, leaving 4.
Replace synchronous XMLHttpRequest with fetch
Setting the third argument of xhr.open() to false stops JavaScript execution until the response arrives. MDN's explanation of synchronous and asynchronous requests also says that synchronous requests freeze the page, and recommends asynchronous requests instead. The Source for this warning was the xhr.open() line (/app.js:3:5).
I switched to fetch and displayed the data when it arrived:
// Load the news with fetch (the page does not stop while waiting)
fetch('/api/news.json')
.then((res) => res.json())
.then((items) => {
document.querySelector('#news').textContent = items[0].title;
});
This removed the row, leaving 3. When I opened the page in Playwright, the news area showed the same Japanese title (the November maintenance notice) both before and after the fix.
Replace unload with pagehide
According to Chrome's explanation of the unload deprecation, a page with an unload listener cannot use the bfcache (back/forward cache), which shows a page immediately when the user goes back or forward. The explanation recommends pagehide for cleanup when the page is left, and visibilitychange (when the state becomes hidden) for saving data. It also says that the unload deprecation is being rolled out gradually to all origins and was completed in Chrome 155.
The test page only sends a log with sendBeacon when the page is left, so I changed the event name to pagehide.
-window.addEventListener('unload', () => {
+window.addEventListener('pagehide', () => {
This removed the row, leaving 2. I opened the page in Playwright and then navigated to about:blank. After the fix, the server received one POST /api/log. With Chrome for Testing 153, the original page with unload also sent it.
The same kind of warning moves to the next place when you fix one
webkitRequestAnimationFrame is used in two places: inside fadeIn and in the first call. After the earlier fixes, those lines had shifted to lines 18 and 20. Even so, only one row appeared in the table before the fix.
As a test, I changed only the first call on line 20 to requestAnimationFrame. The count stayed at 2, and the same warning moved to line 18 (/app.js:18:27).
deprecations: score=0 title="Uses deprecated APIs" displayValue="2 warnings found"
item: source=/app.js:24:21 value="document.createEvent('KeyboardEvents') is deprecated and will be removed. Use new KeyboardEvent() instead."
link: Check the feature status page for more details. https://chromestatus.com/feature/5095987863486464
link: This change will go into effect with milestone 151. https://chromiumdash.appspot.com/schedule
item: source=/app.js:18:27 value="webkitRequestAnimationFrame is vendor-specific. Please use the standard requestAnimationFrame instead."
In this test, only the first call that ran was listed for this kind of warning. I searched the file for other uses of the same API and fixed them all together. After changing both places, this warning disappeared, leaving 1.
Replace createEvent and initKeyboardEvent with the KeyboardEvent constructor
The last warning was for document.createEvent('KeyboardEvents'). The initKeyboardEvent call that follows it is also deprecated, according to MDN's explanation of initKeyboardEvent, which recommends using the KeyboardEvent() constructor instead.
-const ev = document.createEvent('KeyboardEvents');
-ev.initKeyboardEvent('keydown', true, true, window, 'Escape');
+const ev = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true });
document.dispatchEvent(ev);
When I opened the page in Playwright and checked the console, the output before the fix ended with keydown: and nothing after it. After the fix, it showed keydown: Escape. MDN lists key as the fifth argument of initKeyboardEvent, but in Chrome 153 in this test, the key of the event created that way was an empty string. With the old code, the listener that checked the key was not working.
With this change, there were no warnings left.
$ node summarize.mjs out/step5.report.json
lighthouseVersion: 13.6.0 formFactor: mobile locale: en-US
best-practices score: 100
deprecations: score=1 title="Avoids deprecated APIs"
weight in best-practices: 5
The audit now shows as passed ("Avoids deprecated APIs"; the Japanese UI shows a label meaning "Deprecated APIs are not used"), and the Best Practices score is 100. The heading still fades in as before, and its opacity still ends at 1.
If the warning text does not tell you how to fix it, look for the API in the Chrome Platform Status list of deprecated features. In this test, the unload and createEvent rows included links to Chrome Platform Status pages in the JSON results. The official explanation also recommends opening the entry for the API you are using on Chrome Platform Status to confirm why it was deprecated and what to use instead.





