Browser_io. An extension for HTML5 copying ,pasting, saving, opening and drag and drop

I’ve been using the clipboard extension in Defold, but didn’t realize it doesn’t work on HTML5 builds.

My initial attempt was a bit messy, involving Lua modules and modifications to the index.html file. So I went back to the drawing board and created my own extension. Hopefully, it will be useful to others as well.

https://github.com/alfowler1976/defold_browser_io

It provides asynchronous, callback-based functionality with the following commands:

  • browser_io.copy() — copy text to the clipboard

  • browser_io.paste() — read text from the clipboard

  • browser_io.open_file() — open a browser file picker and read a file

  • browser_io.save_file() — download/save data as a file

  • browser_io.set_drop_listener() — receive files dropped onto the browser window

  • browser_io.cancel_drop_listener() — remove the active drop listener

The extension handles the JavaScript/browser interaction internally via Emscripten, so no manual index.html changes are required.

Typical usage is:

browser_io.open_file({ accept = ".txt" }, function(self, result)
    if result.success then
        print(result.name, result.data)
    end
end)

Note: Drag-and-drop events are desktop-only, and some browsers (like Firefox) enforce strict permission prompts for reading the clipboard.

5 Likes