diff --git a/src/frame.js b/src/frame.js index 280ee39..20ef7f6 100644 --- a/src/frame.js +++ b/src/frame.js @@ -81,7 +81,7 @@ function extractFramesFromTimeline(timeline, opts) { const startTs = (opts.timeOrigin || events[0].ts) / 1000; const endTs = events[events.length - 1].ts / 1000; - const rawScreenshots = events.filter(e => e.cat.includes(screenshotTraceCategory)); + const rawScreenshots = events.filter(e => e.cat.includes(screenshotTraceCategory) && e.ts >= startTs * 1000); const frames = rawScreenshots.map(function (evt) { const base64img = evt.args && evt.args.snapshot; const timestamp = evt.ts / 1000; diff --git a/test/frame.js b/test/frame.js index fc9e3fb..553ebc8 100644 --- a/test/frame.js +++ b/test/frame.js @@ -47,11 +47,13 @@ test('extract frames should support json', async t => { const data = await frame.extractFramesFromTimeline(trace); t.is(data.startTs, 103204916.772, 'data.startTs doesn\'t match expected value'); t.true(Array.isArray(data.frames), 'Frames is not an array'); + t.is(data.frames.length, 7, 'Number of frames is incorrect'); }); test('extract frames from timeline supports options', async t => { - const data = await frame.extractFramesFromTimeline('./assets/progressive-app.json', {timeOrigin: 103205446186}); - t.is(data.startTs, 103205446.186, 'data.startTs doesn\'t match supplied timeOrigin value'); + const data = await frame.extractFramesFromTimeline('./assets/progressive-app.json', {timeOrigin: 103206183179}); + t.is(data.startTs, 103206183.179, 'data.startTs doesn\'t match supplied timeOrigin value'); t.truthy(data.endTs, 'data.endTs doesn\'t exist'); t.true(Array.isArray(data.frames), 'Frames is not an array'); + t.is(data.frames.length, 4, 'Frames were not filtered'); });