GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

fileOpen() function doesn't reject promise when user dismiss file picker prompt without selecting a file #33

Closed mikeAtHexosIp closed 3 years ago

mikeAtHexosIp commented 3 years ago

The API works fine when selecting files and also handles rejection when the chosen file is not valid, but when the user dismiss the file picker prompt without selecting any file, execution gets stuck in await fileOpen().

Code sample:

let fileHandle;
try {
   fileHandle = await fileOpen({
     mimeTypes: ['text/csv'],
     extensions: ['.csv'],
   });
} catch(error) {
   console.log(error); // Nothing happens here
}

AC: Reject promise in fileOpen function when file picker prompt is dismissed

tomayac commented 3 years ago

Thanks for filing this, but I can't reproduce the reported issue. If you open the demo and place a breakpoint on line 47 of script.mjs with DevTools and then click the Open Image File button, you can see that the demo catches the error and checks if the reason is an abort:

Screen Shot 2021-02-26 at 16 15 48
Snugug commented 3 years ago

@tomayac thanks for looking into this! I just gave this a try in Firefox Developer Edition, latest version, and if I cancel from Open Image File button it doesn't hit the breakpoint. I think it may have something to do with the polyfill fallback.

tomayac commented 3 years ago

Just discussed this offline with @Snugug. I’ll make sure this throws in the fallback case, too.

tomayac commented 3 years ago

@mikeAtHexosIp Thanks again for reporting this. I have just release v0.14.0 that includes this fix.

tomayac commented 3 years ago

Safari Web Inspector:

Screen Shot 2021-02-26 at 17 47 19