From 3b82c832a272842154079087a85cfef914b55eff Mon Sep 17 00:00:00 2001 From: Chris Yi Date: Thu, 13 Mar 2025 13:57:24 +0800 Subject: [PATCH] fix the browser crashes when calling getAsFileSystemHandle --- src/file-selector.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/file-selector.js b/src/file-selector.js index ef5fef76..2671746c 100644 --- a/src/file-selector.js +++ b/src/file-selector.js @@ -122,7 +122,13 @@ function flatten(items) { } function fromDataTransferItem(item, entry) { - if (typeof item.getAsFileSystemHandle === "function") { + // Check if we're in a secure context; due to a bug in Chrome (as far as we know) + // the browser crashes when calling this API (yet to be confirmed as a consistent behaviour). + // + // See: + // - https://issues.chromium.org/issues/40186242 + // - https://github.com/react-dropzone/react-dropzone/issues/1397 + if (globalThis.isSecureContext && typeof item.getAsFileSystemHandle === 'function') { return item.getAsFileSystemHandle().then(async (h) => { const file = await h.getFile(); file.handle = h;