diff --git a/x-pack/plugins/reporting/export_types/printable_pdf/server/lib/screenshots.js b/x-pack/plugins/reporting/export_types/printable_pdf/server/lib/screenshots.js index 0845ecad65664..57e17f924bb11 100644 --- a/x-pack/plugins/reporting/export_types/printable_pdf/server/lib/screenshots.js +++ b/x-pack/plugins/reporting/export_types/printable_pdf/server/lib/screenshots.js @@ -133,7 +133,13 @@ export function screenshotsObservableFactory(server) { } } - return Promise.all(renderedTasks); + // The renderComplete fires before the visualizations are in the DOM, so + // we wait for the event loop to flush before telling reporting to continue. This + // seems to correct a timing issue that was causing reporting to occasionally + // capture the first visualization before it was actually in the DOM. + const hackyWaitForVisualizations = () => new Promise(r => setTimeout(r, 100)); + + return Promise.all(renderedTasks).then(hackyWaitForVisualizations); }, args: [layout.selectors.renderComplete, captureConfig.loadDelay], awaitPromise: true,