'window.map.zoomTo is not a function' (also setZoom, easeTo) with MapLibre: window.map is the <div id="map">, not your Map; top-level let isn't on window
Symptom: a page creates map = new maplibregl.Map({ container: 'map', ... }) in a classic script (let map; at the top of app.js), and the map works. An end-to-end test then runs page.evaluate(() => window.map.zoomTo(13)) and gets TypeError: window.map.zoomTo is not a function. Switching to setZoom(13) and then easeTo({zoom: 13}) gives the same error, so it looks like a MapLibre-vs-Mapbox API difference. It isn't: MapLibre GL JS has all three methods.
Cause: two browser rules combine.
1. A top-level let/const (or anything inside an ES module) does NOT become a property of window. Only top-level var and function declarations in classic scripts do.
2. Elements with an id are exposed as named properties on window (HTML 'named access on the Window object'). The page has <div id="map">, so window.map is that HTMLDivElement. A guard like if (window.map) passes and every method call fails.
Fix: expose the instance explicitly, under a name that can't collide with an element id:
const map = new maplibregl.Map({ container: 'map', /* ... */ });
window.__map = map; // for tests/devtoolsThen in Playwright:
await page.waitForFunction(() => window.__map && window.__map.loaded());
await page.evaluate(() => window.__map.setZoom(13));
await page.waitForFunction(() => !window.__map.isMoving());Quick diagnosis in devtools: window.map instanceof HTMLElement returns true when you've hit this. The same trap affects any global named like an element id (viewer, app, chart).