Guard against screenshot capture failure

Summary:
Bit off an odd one but according to the crash report in T107008330,
the screenshot can sometimes be not a real buffer. This may not actually
fix things but should give us some more insights into what's up.

Changelog: Better handling of screenshot taking in navigation

Reviewed By: mweststrate

Differential Revision: D32797863

fbshipit-source-id: 6d16ccb82fb8258591f9bc5f79c00811b18b9c51
This commit is contained in:
Pascal Hartig
2021-12-03 03:28:42 -08:00
committed by Facebook GitHub Bot
parent c9f623edf3
commit 77d7ec2efb

View File

@@ -74,6 +74,12 @@ export function plugin(client: PluginClient<Events, Methods>) {
}); });
const screenshot: Buffer = await client.device.screenshot(); const screenshot: Buffer = await client.device.screenshot();
if (screenshot.byteLength === 0) {
console.warn(
'[navigation] Could not retrieve valid screenshot from the device.',
);
return;
}
const blobURL = URL.createObjectURL(bufferToBlob(screenshot)); const blobURL = URL.createObjectURL(bufferToBlob(screenshot));
// this process is async, make sure we update the correct one.. // this process is async, make sure we update the correct one..
const navigationEventIndex = navigationEvents const navigationEventIndex = navigationEvents