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

Opening a file via legacy-API throws AbortError #36

Closed dwelle closed 3 years ago

dwelle commented 3 years ago

Steps:

  1. in Firefox, open a file that has no extension
  2. instead of resolving with the Blob, it throws AbortError

sandbox: https://srzn8.csb.app/

(via https://github.com/excalidraw/excalidraw/issues/3155)

Introduced in https://github.com/GoogleChromeLabs/browser-fs-access/commit/5d8a551af106121d010c1c50ca4a15d3cb0b189d

dwelle commented 3 years ago

Can be hack-fixed by running the cancelDetector in a next tick, but I'd still be hesitant to call it a surefire solution:

const cancelDetector = () => {
  window.removeEventListener('focus', cancelDetector);
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      if (input.files.length === 0) {
        reject(
          new DOMException('The user aborted a request.', 'AbortError')
        );
      }
    });
  });
};