Chromely
Chromely copied to clipboard
Writing to files using File System Access API fails
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
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.
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 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.
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
I had the same issue with the File System Access API. I want to show SaveAs dialog. Do you have any suggestions?