chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.98k stars 280 forks source link

Writing to files using File System Access API fails #328

Open CarlosGabado opened 3 years ago

CarlosGabado commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

CarlosGabado commented 3 years ago

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 commented 2 years ago

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