Skip to Content
defold-typescript libraries
alfowler1976

alfowler1976/defold_browser_io/browser_io

Callback-based browser clipboard and file I/O for Defold. Browser operations are available on HTML5 builds; capability functions report support in the current browser.

  • GitHub: alfowler1976/defold_browser_io — pinned to v0.9.0 (released while Defold 1.13.2 was current)
    1. Pick a release from alfowler1976/defold_browser_io releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as browser_io from "browser_io"
  • Asset Portal: defold_browser_io

Functions

browser_io.is_supported(): boolean

Returns true when the extension is running on an HTML5 build. This is a platform check; use can_* functions for individual browser capabilities.

Returns

  • supported: boolean — True on HTML5, false on other platforms.

browser_io.can_copy(): boolean

Returns true when clipboard text writing is available in the current browser context.

Returns

browser_io.can_paste(): boolean

Returns true when clipboard text reading is available in the current browser context. Browser permission or user-gesture rules can still reject an individual request.

Returns

browser_io.can_open_file(): boolean

Returns true when the browser exposes the APIs required to open and read a file.

Returns

browser_io.can_save_file(): boolean

Returns true when the browser exposes the APIs required to create a downloadable file.

Returns

browser_io.can_drop_files(): boolean

Returns true when the browser exposes drag-and-drop and file-reading APIs. This does not guarantee that external file dropping is practical on touch-only devices.

Returns

  • supported: boolean — True when drag-and-drop APIs are available.

browser_io.copy(text: string, callback: function): number

Copies UTF-8 text to the browser clipboard asynchronously. Call from a direct user interaction where required by the browser.

Parameters

  • text: string — Text to copy.
  • callback: function — Called as callback(self, result). result contains success, cancelled, operation, and error when applicable.

Returns

  • request_id: number — Request identifier.

browser_io.paste(callback: function): number

Reads UTF-8 text from the browser clipboard asynchronously. Call from a direct user interaction where required by the browser.

Parameters

  • callback: function — Called as callback(self, result). On success result.data contains the clipboard text and result.size contains its byte length.

Returns

  • request_id: number — Request identifier.

browser_io.open_file(2 overloads): number

Opens the browser file picker and asynchronously reads one file. Supported forms are open_file(callback), open_file(nil, callback), and open_file(options, callback).

  1. (callback: function)

    Parameters

    • callback: function — Called as callback(self, result). On success result.name, result.data, and result.size are set. Empty files return data as an empty string and size as 0.
  2. (options: table | undefined, callback: function)

    Parameters

    • options: table | undefined — Optional table. accept is an HTML accept string and max_size is the maximum file size in bytes. The default max_size is 16 MiB.
    • callback: function — Called as callback(self, result). On success result.name, result.data, and result.size are set. Empty files return data as an empty string and size as 0.

Returns

  • request_id: number — Request identifier.

browser_io.save_file(2 overloads): number

Creates a browser download from a Lua string. Binary strings are supported. Supported forms are save_file(filename, data, callback), save_file(filename, data, nil, callback), and save_file(filename, data, options, callback).

  1. (filename: string, data: string, callback: function)

    Parameters

    • filename: string — Suggested downloaded filename.
    • data: string — File bytes.
    • callback: function — Called as callback(self, result) when the download has been handed to the browser.
  2. (filename: string, data: string, options: table | undefined, callback: function)

    Parameters

    • filename: string — Suggested downloaded filename.
    • data: string — File bytes.
    • options: table | undefined — Optional table. mime_type defaults to application/octet-stream.
    • callback: function — Called as callback(self, result) when the download has been handed to the browser.

Returns

  • request_id: number — Request identifier.

browser_io.set_drop_listener(2 overloads): boolean

Registers a persistent file drag-and-drop listener on the browser window. Supported forms are set_drop_listener(callback), set_drop_listener(nil, callback), and set_drop_listener(options, callback).

  1. (callback: function)

    Parameters

    • callback: function — Called for each completed drop as callback(self, result). On success result.name, result.data, and result.size are set.
  2. (options: table | undefined, callback: function)

    Parameters

    • options: table | undefined — Optional table. accept filters dropped files and max_size limits the number of bytes read. The default max_size is 16 MiB.
    • callback: function — Called for each completed drop as callback(self, result). On success result.name, result.data, and result.size are set.

Returns

  • enabled: boolean — True when the listener was enabled on HTML5, false on unsupported build targets.

browser_io.cancel_drop_listener()

Removes the persistent drag-and-drop listener and releases its Lua callback.

On this page