Sfoglia il codice sorgente

workaround chrome crash (#4310)

* workaround chrome crash

fixes #4133

* Update packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

---------

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Mikael Finstad 2 anni fa
parent
commit
8673335d47

+ 6 - 2
packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js

@@ -43,8 +43,12 @@ async function* createPromiseToAddFileOrParseDirectory (entry, relativePath, las
 export default async function* getFilesFromDataTransfer (dataTransfer, logDropError) {
   const entries = await Promise.all(Array.from(dataTransfer.items, async item => {
     const lastResortFile = item.getAsFile() // Chromium bug, see https://github.com/transloadit/uppy/issues/3505.
-    const entry = await item.getAsFileSystemHandle?.()
-      ?? getAsFileSystemHandleFromEntry(item.webkitGetAsEntry(), logDropError)
+    let entry
+    // IMPORTANT: Need to check isSecureContext *first* or else Chrome will crash when running in HTTP:
+    // https://github.com/transloadit/uppy/issues/4133
+    if (window.isSecureContext && item.getAsFileSystemHandle != null) entry = await item.getAsFileSystemHandle()
+    // fallback
+    entry ??= getAsFileSystemHandleFromEntry(item.webkitGetAsEntry(), logDropError)
 
     return { lastResortFile, entry }
   }))