Skip to content

Commit df66419

Browse files
committed
refactor: remove getEntriesByType shim now that snippets use buffered observer
1 parent fd6a78d commit df66419

1 file changed

Lines changed: 0 additions & 30 deletions

File tree

cli/src/runner.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,6 @@ import { chromium } from "playwright";
33
const DEFAULT_VIEWPORT = { width: 1280, height: 800 };
44
const DEFAULT_NAV_TIMEOUT = 30000;
55

6-
// Chrome does not expose largest-contentful-paint or layout-shift entries via
7-
// performance.getEntriesByType — they are only delivered through observers.
8-
// The snippets' synchronous return path assumes otherwise (works in
9-
// long-lived consoles where entries leaked into the timeline). To make
10-
// snippets work unmodified in headless, we capture entries via a pre-nav
11-
// observer and shim getEntriesByType to return them.
12-
const WARMUP_SCRIPT = `
13-
(() => {
14-
window.__wps = { lcp: [], layoutShift: [] };
15-
try {
16-
new PerformanceObserver((list) => {
17-
for (const e of list.getEntries()) window.__wps.lcp.push(e);
18-
}).observe({ type: "largest-contentful-paint", buffered: true });
19-
} catch {}
20-
try {
21-
new PerformanceObserver((list) => {
22-
for (const e of list.getEntries()) window.__wps.layoutShift.push(e);
23-
}).observe({ type: "layout-shift", buffered: true });
24-
} catch {}
25-
26-
const orig = performance.getEntriesByType.bind(performance);
27-
performance.getEntriesByType = function (type) {
28-
if (type === "largest-contentful-paint") return window.__wps.lcp.slice();
29-
if (type === "layout-shift") return window.__wps.layoutShift.slice();
30-
return orig(type);
31-
};
32-
})();
33-
`;
34-
356
// Snippets are IIFEs. Playwright evaluates a string as an expression, so we
367
// trim trailing semicolons to keep the IIFE call as a single expression and
378
// recover its return value in Node.
@@ -50,7 +21,6 @@ export async function runSnippets({
5021
const browser = await chromium.launch({ headless });
5122
try {
5223
const context = await browser.newContext({ viewport });
53-
await context.addInitScript(WARMUP_SCRIPT);
5424
const page = await context.newPage();
5525

5626
const pageErrors = [];

0 commit comments

Comments
 (0)