Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Writing to files using File System Access API fails #328

Open
CarlosGabado opened this issue Jun 17, 2021 · 5 comments
Open

Writing to files using File System Access API fails #328

CarlosGabado opened this issue Jun 17, 2021 · 5 comments

Comments

@CarlosGabado
Copy link

CarlosGabado commented Jun 17, 2021

I have a that reads and writes local files using File System Access API. When run in a browser (Chrome or Edge that support it), both reading and writing files work fine.

When the app is run in Electron, reading works but writing fails due to: Uncaught (in promise) DOMException: The request is not allowed by the user agent or the platform in the current context.

Here the function
`
async function chooseAndWriteToFile(contents) {
const fileHandle = await window.showSaveFilePicker()

  const descriptor = {
    writable: true,
    mode: "readwrite"
  }
  const permissionState = await fileHandle.requestPermission(descriptor)
  console.log(window.isSecureContext)
  console.log(permissionState)

  const writable = await fileHandle.createWritable()
  await writable.write(contents)
  await writable.close()
}

`

@mattkol
Copy link
Member

mattkol commented Jun 17, 2021

@CarlosGabado

When the app is run in Electron, reading works but writing fails due to: Uncaught (in promise) DOMException:

This is failing in Electron or Chromely?

If you meant Chromely, I will suggest you run the same files that succeed in Chrome or Edge in Chromely itself as-is and see what happens.

@CarlosGabado
Copy link
Author

I'm running in Chromely

If you meant Chromely, I will suggest you run the same files that succeed in Chrome or Edge in Chromely itself as-is and see what happens.

If I open the html file with the js write function in the browser (Chrome) it will save the contents to a file, but running in my Chromely App the same html file it will create the file but it will not write the contents

@mattkol
Copy link
Member

mattkol commented Jun 17, 2021

@CarlosGabado I am personally not familiar with the library you are using. Others may help.

Also see if it has to do with the download handler not implemented:
#189

This is also a related issue:
#170

If all those links do not help, you may have to include a skeletal project.

@CarlosGabado
Copy link
Author

I manage to write files now with the download workaround
using #189 and with FileSaver.js

But writing directly with the File System Access API is not possible

@siquylee
Copy link

I had the same issue with the File System Access API. I want to show SaveAs dialog. Do you have any suggestions?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants