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.37k stars 82 forks source link

supported always returns false when in iframe #138

Closed msvinth-work closed 1 year ago

msvinth-work commented 1 year ago

The supported function seems to have a bug due to "else if" instead of "if" and always return false even when in a first-party iframe.

In line 39 in main/src/supported.mjs

Should properly be

 } 
 if ('showOpenFilePicker' in self) {
    return 'showOpenFilePicker';
 }

instead of

  } else if ('showOpenFilePicker' in self) {
    return 'showOpenFilePicker';
  }
tomayac commented 1 year ago

You’re right, this isn’t working as intended.

I think there’s a return 'showOpenFilePicker(); missing right after https://github.com/GoogleChromeLabs/browser-fs-access/blob/b52e7bfc5ea93a259d0191eaf147fbe2d40e98d0/src/supported.mjs#L35

I’ll properly test this after the weekend.

tomayac commented 1 year ago

My brain was in weekend mode. Your suggestion was correct. I have also simplified this, since it still had artifacts of the previous version of the File System Access API. I have also added the different iframes to the demo. Thanks again for filing this.