This topic is locked
[SOLVED]

Get Content FROM Clipboard?

2/22/2026 09:55:00
PHPRunner General questions
T
telematics author

dear community,

is there a way inside a button event to get data from the clipboard and process it?

the javascript function "navigator.clipboard.readText()" allows this only in the "Client after" task, but I would like to process it on server side (analyze, store, ...).

regards
Helmut

ChatGPT 2/22/2026

Hi Helmut,

In PHPRunner, handling clipboard data directly on the server side is not straightforward because clipboard access is primarily a client-side operation. You can use JavaScript to read from the clipboard, but since the clipboard content is only accessible in the client's browser environment, you will need to send that data to the server after retrieving it.

Here’s a general approach to achieve this:

  1. Use JavaScript to Read from the Clipboard: You can use navigator.clipboard.readText() in a JavaScript event (like a button click) to get the clipboard data.


  2. Send the Data to the Server: Once you have the data from the clipboard, you can use AJAX to send it to a server-side script for processing.


  3. Process the Data on the Server: In your server-side code (PHP), you can analyze, store, or perform any other operations with the received data.



Example Implementation:

  1. Client-side JavaScript:
    You need to create a button and add a click event to it that reads from the clipboard.

    function getClipboardData() {
    navigator.clipboard.readText().then(function(text) {
    // Send the clipboard data to the server using AJAX
    $.ajax({
    url: 'your_server_script.php', // Replace with your server-side script
    method: 'POST',
    data: { clipboardData: text },
    success: function(response) {
    console.log('Server response:', response);
    },
    error: function(jqXHR, textStatus, errorThrown) {
    console.error('Error:', textStatus, errorThrown);
    }
    });
    }).catch(function(error) {
    console.error('Failed to read clipboard contents: ', error);
    });
    }

    // Attach this function to your button
    document.getElementById('yourButtonId').addEventListener('click', getClipboardData);

  2. Server-side PHP (your_server_script.php):
    In your PHP script, you can access the clipboard data sent via the AJAX request.

    <?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['clipboardData'])) {
    $clipboardData = $_POST['clipboardData'];

    // Process the clipboard data (analyze, store, etc.)
    // For example, you could store it in a database or perform some analysis.

    // Send a response back to the client
    echo json_encode(['status' => 'success', 'data' => $clipboardData]);
    } else {
    echo json_encode(['status' => 'error', 'message' => 'No data received.']);
    }
    ?>


Conclusion:

While you cannot directly access the clipboard on the server side, this method allows you to effectively retrieve the data on the client side and then send it to the server for processing. Make sure to handle any permissions and security considerations for clipboard access in your application.

If you have any further questions or need more help, feel free to ask!

Best regards,
[Your Name]

T
telematics author 2/22/2026

finally, I could solve the problem myself.

navigator.clipboard.readText() fires an async event, so I have to submit() it inside the .then function.

this runs in Client Before:

navigator.clipboard.readText()
.then(function(text){
params['text_from_clipboard'] = text;
submit(); // must be submitted, because it is async event
})

return false;

the corresponding Server code can easy process the $params['text_from_clipboard'] and continue.

btw: the ChatGPT generated solution below could not help much

regards
Helmut