diff options
| author | Ray <[email protected]> | 2023-01-04 20:13:44 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-01-04 20:13:44 +0100 |
| commit | ce8000ee7e3c1e07bd747e71872200311038d090 (patch) | |
| tree | 4f3e727cd7c893c4e518b60bc4717193035ed531 /src | |
| parent | 89755e52bf066e66dcfac2f2f52f6806ff02a693 (diff) | |
| download | raylib-ce8000ee7e3c1e07bd747e71872200311038d090.tar.gz raylib-ce8000ee7e3c1e07bd747e71872200311038d090.zip | |
REVIEWED: `GetClipboardText()` on `PLATFORM_WEB`
Diffstat (limited to 'src')
| -rw-r--r-- | src/rcore.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/rcore.c b/src/rcore.c index d1763294..da943657 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1945,7 +1945,21 @@ const char *GetClipboardText(void) return glfwGetClipboardString(CORE.Window.handle); #endif #if defined(PLATFORM_WEB) - return emscripten_run_script_string("navigator.clipboard.readText()"); + // Accessing clipboard data from browser is tricky due to security reasons + // The method to use is navigator.clipboard.readText() but this is an asynchronous method + // that will return at some moment after the function is called with the required data + emscripten_run_script_string("navigator.clipboard.readText() \ + .then(text => { document.getElementById('clipboard').innerText = text; console.log('Pasted content: ', text); }) \ + .catch(err => { console.error('Failed to read clipboard contents: ', err); });" + ); + + // The main issue is getting that data, one approach could be using ASYNCIFY and wait + // for the data but it requires adding Asyncify emscripten library on compilation + + // Another approach could be just copy the data in a HTML text field and try to retrieve it + // later on if available... and clean it for future accesses + + return NULL; #endif return NULL; } |
