<input type="file"/> not working in DesktopHTMLViewer

I’m trying to open local audio files with the input tag <input type="file"/> to play them with wavesurfer.js in a DesktopHTMLViewer.

But nothing happens when I click the button in the viewer.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
     </head>
  <body>
    <input type="file"/>  
    </body>
</html>

This code works as expected in Safari but not in a DesktopHTMLViewer.

Is it a security issue or something else at play here?

macOS Sonoma, XOJO 2023R3

I have run into similar issues and believe it’s a restriction on the browser side.

The workaround is to have the button call executeInXojo and capture it in the JavascriptRequest event. Display your open dialog and get a filename to open. Then write a separate javascript in your page that loads in that filename via ExecuteJavascript.

Apple is increasing the security over time and breaking things.

Check if limiting the accepted file types something changes as

<input type="file" accept=".xls,.xlsx,.txt,.csv"/>

Thank you Christian and Rick.
Unfortunately <input type="file" accept=".xls,.xlsx,.txt,.csv"/> makes no difference.
I’m not sure I fully understand Christians advise but I’ll see what I can make out of it.

You need a htmlviewer, that accepts file like our WKWebViewControlMBS control in MBS Xojo Plugins.

and there you implement the event:

to allow the user to pick the folderitem and restrict it as you need. Or even automatically choose file for them.

This is exactly what I want to achieve!
I want to choose the file in XOJO and play/show it in the HTMLViewer using wavesurfer.js.
Actually I don’t want the user to pick the file – this was only for testing.

Can I find an example of how to use runOpenPanelWithParameters somewhere?

There is no example directly.
You can take the example from /Mac64bit/WebKit2/WebView folder and then add this event and load the website to try it.

I’ve added the runOpenPanelWithParameters event with this code:

Var URLs() As NSURLMBS
MediaFile = FolderItem.ShowOpenFileDialog("")

If MediaFile <> NIL And MediaFile.Exists Then
  Var TheURL As New NSURLMBS(MediaFile)
  URLs.Add(TheURL)
Else 
  URLs = NIL
End if

Me.runOpenPanelWithParametersCompleted(URLs)

– and it works as expected.

But I’m uncertain if I do it the proper way cause the code is mainly based on trial and error :slight_smile: