i have a working nodejs/puppeteer solution for rendering a map to screenshot. the code works great with an interactive/visible browser, but does not render the page when run headless. if i drop back to an ancient mapbox (build 25) then it does render headless but mapbox is missing other functionality in that old build that i need.
is there anything i can do to make this work. code to repro below.
(async() => {
console.log("test starting");
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({headless: false,userDataDir: "data"});
const page = (await browser.pages())[0];
await page.goto('file://map.html');
await page.waitForFunction('document.querySelector("#sync").textContent.includes("sync")');
await page.setViewport({ width: 800, height: 480 });
await page.screenshot({path: 'map.png'});
await browser.close();
})();
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:800px; height:480px; }
</style>
</head>
<body>
<div id='map'></div>
<div id='sync'></div>
<script>
const outputContainer = document.getElementById('sync');
mapboxgl.accessToken = '**token**';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-122.3351,47.6080],
zoom: 7
});
map.once('idle', (e) => {
console.log("map loaded");
outputContainer.innerHTML += `sync<br>`;
});
</script>
</body>
</html>