feat: add support for long-animation-frame script attribution (#49706)

* feat: add support for `long-animation-frame` script attribution

* docs: document `AlwaysLogLOAFURL`

* chore: add test

* docs: adjust docs as per PR comment

* fix: test failures

* chore: simplify test

* fix: tests on Windows and Linux
This commit is contained in:
Niklas Wenzel
2026-02-11 18:34:22 +01:00
committed by GitHub
parent ff2df2c98a
commit ce47542ccd
5 changed files with 112 additions and 0 deletions

View File

@@ -3280,6 +3280,29 @@ describe('chromium features', () => {
expect(rgb).to.equal('');
});
});
describe('long-animation-frame', () => {
it('should include script attribution on custom protocols if AlwaysLogLOAFURL is enabled', async () => {
const rc = await startRemoteControlApp(['--enable-features=AlwaysLogLOAFURL']);
const hasAttribution = await rc.remotely(async (fixture: string) => {
const { BrowserWindow, protocol, net } = require('electron/main');
const { pathToFileURL } = require('node:url');
protocol.handle('custom', () => net.fetch(pathToFileURL(fixture).toString()));
// `show: true` is necessary on Windows and Linux due to https://github.com/electron/electron/issues/32001
const w = new BrowserWindow({ show: true });
await w.loadURL('custom://my-url');
const hasAttribution = await w.webContents.executeJavaScript('hasAttributionPromise');
global.setTimeout(() => require('electron').app.quit());
return hasAttribution;
}, path.join(fixturesPath, 'chromium', 'long-animation-frame.html'));
expect(hasAttribution).to.be.true();
});
});
});
describe('font fallback', () => {

View File

@@ -0,0 +1,29 @@
<!doctype html>
<html>
<body>
<div id="update"></div>
<script>
var hasAttributionPromise = new Promise((resolve) => {
new PerformanceObserver((list) => {
const entries = list.getEntries();
const has_attribution =
entries.length > 0 &&
entries.every(
({ scripts }) =>
scripts.length > 0 &&
scripts.every(({ sourceURL }) => sourceURL === location.href),
);
resolve(has_attribution);
}).observe({ entryTypes: ["long-animation-frame"] });
// Produce a long animation frame
requestAnimationFrame(() => {
const before = performance.now();
document.querySelector("#update").innerHTML = "Update";
while (performance.now() < before + 60) {}
requestAnimationFrame(() => {});
});
});
</script>
</body>
</html>