Spaces:
Sleeping
Sleeping
File size: 1,418 Bytes
74d06a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | const puppeteer = require('puppeteer');
(async () => {
try {
const browser = await puppeteer.launch({ headless: 'new' });
const page = await browser.newPage();
await page.setContent(`
<style>
#box { width: 0px; height: 100px; background: blue; transition: width 1s linear; }
#box.active { width: 500px; }
</style>
<div id="box"></div>
<script>
// Force the browser to register the initial state
document.getElementById('box').getBoundingClientRect();
requestAnimationFrame(() => {
document.getElementById('box').classList.add('active');
});
</script>
`);
const client = await page.target().createCDPSession();
await client.send('Emulation.setVirtualTimePolicy', { policy: 'pause' });
for(let i=0; i<6; i++) {
await client.send('Emulation.setVirtualTimePolicy', {
policy: 'advance',
budget: 200
});
await new Promise(resolve => client.once('Emulation.virtualTimeBudgetExpired', resolve));
const width = await page.evaluate(() => {
// Force style recalc
return window.getComputedStyle(document.getElementById('box')).width;
});
console.log(`Frame ${i} (+200ms): width = ${width}`);
}
await browser.close();
} catch (e) {
console.error('Error:', e);
process.exit(1);
}
})();
|