Chromely icon indicating copy to clipboard operation
Chromely copied to clipboard

Writing to files using File System Access API fails

Open CarlosGabado opened this issue 4 years ago • 5 comments
trafficstars

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()
}

`

CarlosGabado avatar Jun 17 '21 10:06 CarlosGabado

@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.

mattkol avatar Jun 17 '21 11:06 mattkol

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

CarlosGabado avatar Jun 17 '21 11:06 CarlosGabado

@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: https://github.com/chromelyapps/Chromely/issues/189

This is also a related issue: https://github.com/chromelyapps/Chromely/issues/170

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

mattkol avatar Jun 17 '21 12:06 mattkol

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

CarlosGabado avatar Jun 17 '21 16:06 CarlosGabado

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

siquylee avatar Oct 30 '21 05:10 siquylee