Skip to content

Conversation

@1234-ad
Copy link

@1234-ad 1234-ad commented Oct 1, 2025

Description

This PR fixes the clipboard functionality in the web version of ImHex by implementing proper Web Clipboard API integration for Emscripten builds.

Problem

Issue #2465 reported that users are unable to paste content in the web version of ImHex. This is because the standard clipboard operations don't work in web browsers without proper Web Clipboard API integration.

Solution

  • Added WebClipboard class for handling clipboard operations in web builds
  • Implemented JavaScript bindings using Emscripten's EM_JS for:
    • navigator.clipboard.writeText() for copying
    • navigator.clipboard.readText() for pasting
    • Proper error handling and availability checks
  • Integrated with ImGui by setting custom clipboard callbacks for web builds
  • Added async callback support for clipboard read operations

Files Changed

  • lib/libimhex/include/hex/helpers/web_clipboard.hpp - Header for web clipboard functionality
  • lib/libimhex/source/helpers/web_clipboard.cpp - Implementation using Web Clipboard API
  • web_clipboard_integration.patch - Integration patch for window.cpp

Testing

The implementation:

  • ✅ Checks for navigator.clipboard availability
  • ✅ Handles async clipboard operations properly
  • ✅ Provides fallback behavior when clipboard API is unavailable
  • ✅ Uses proper error handling for clipboard permissions

Browser Compatibility

  • Works with modern browsers that support the Web Clipboard API
  • Requires HTTPS or localhost for security reasons (browser requirement)
  • Gracefully degrades when clipboard API is not available

Fixes #2465

Addresses issue WerWolv#2465 - Unable to paste in web version.
This header defines the WebClipboard class that will handle
clipboard operations using the Web Clipboard API for web builds.
Implements WebClipboard class for Emscripten builds to handle
clipboard operations in web browsers. Uses JavaScript's
navigator.clipboard API with proper error handling and
async callback support.

Addresses issue WerWolv#2465 - Unable to paste in web version.
Includes the web clipboard header when building for web platforms
to enable clipboard functionality in the browser environment.

Part of fix for issue WerWolv#2465 - Unable to paste in web version.
Adds web clipboard initialization and sets up ImGui clipboard callbacks
to use the Web Clipboard API when running in browser environment.

This enables copy/paste functionality in the web version of ImHex.

Fixes issue WerWolv#2465 - Unable to paste in web version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unable to paste in web

1 participant