TheLazyDogsBack
TheLazyDogsBack

Reputation: 237

Calling showOpenFilePicker : how avoid "must come from gesture" when calling class methods

Accessing the local filesystem a la: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle

If I inline all my code for the show(Open|Save)FilePicker API logic directly in my button event closure or call plain fn's then things work ok. However, if I define a class w/helper methods and call those from my event-handler, and those helpers call the file pickers, then I get this error:

Uncaught DOMException: Failed to execute 'showOpenFilePicker' on 'Window': Must be handling a user gesture to show a file picker.

I assume the the security system is looking at this to establish the gesture context - is there a way to re-establish this context with code running in my class?

Upvotes: 2

Views: 4597

Answers (1)

TheLazyDogsBack
TheLazyDogsBack

Reputation: 237

Turns out the class methods were a red herring -- the issue has to do with async code and promises -- this is what looses the context and causes the error. You need to make any calls to the FS without any promise chaining.

Upvotes: 2

Related Questions