From 197e2093211e1899563aa2d62045a66b5072a955 Mon Sep 17 00:00:00 2001 From: Chris Johnson <49479599+workeffortwaste@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:19:23 +0000 Subject: [PATCH] Respect start frame with timeweb --- index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.js b/index.js index 2408b62..df89c87 100644 --- a/index.js +++ b/index.js @@ -439,6 +439,26 @@ const videoExport = async (options) => { /* Progress the animation and take a screenshot */ let frameStep = 0 + let wasteStep = 0 + + /* Timeweb won't properly jump to a startFrame for me so we're going to waste some frames before we start capturing to ensure compatibility with the custom startFrame. */ + if (options.advance === 'timeweb') { + for (let x = 0; x < startFrame; x++) { + /* Time in ms to advance the frames */ + const interval = 1000 / options.fps + + /* Shift the ms along slightly to avoid errors with weird gsap code */ + const ms = interval * wasteStep + 1 + await page.evaluate(async (ms) => { + /* Prepare frame */ + await window.timeweb.goTo(ms) + }, ms) + + wasteStep++ + } + } + + /* The recording loop */ for (let x = startFrame; x < endFrame; x++) { const frame = x / duration