monkeytype icon indicating copy to clipboard operation
monkeytype copied to clipboard

Clipboard input in many devices is not detected as paste

Open Aaryan-Dadu opened this issue 10 months ago • 8 comments

Did you clear cache before opening an issue?

  • [x] I have cleared my cache

Is there an existing issue for this?

  • [x] I have searched the existing open and closed issues

Does the issue happen when logged in?

Yes

Does the issue happen when logged out?

Yes

Does the issue happen in incognito mode when logged in?

Yes

Does the issue happen in incognito mode when logged out?

Yes

Account name

aaryandadu

Account config

No response

Current Behavior

when using monkeytype on many devices text inserted via the clipboard is not detected as a paste action thus leading to absurd results. This most probably caused because clipboard based input method does not trigger OS level paste event that the event listeners listens for.

https://github.com/user-attachments/assets/511a07f5-cf57-47ed-b336-f653314f244a

Expected Behavior

This type of paste by the clipboard should be disabled. I looked into the possible solutions we can move towards but I think that the better approach would be to detect max 1 character per keystroke, multiple characters in one key stroke could be blocked.

Steps To Reproduce

  1. Use Gboard in any device or built-in clipboard by One UI.
  2. Copy the text from the preview in monkeytype in any mode
  3. Paste the copied text using the clipboard

https://github.com/user-attachments/assets/b6b7abc3-b5d8-46ab-a490-383128a217ec

Environment

  • OS:
  • Browser:
  • Browser Version:

Anything else?

No response

Aaryan-Dadu avatar Jan 15 '26 18:01 Aaryan-Dadu

I can reproduce this on mobile (Gboard / One UI). It looks like clipboard insertion often doesn’t trigger a native paste event, so Monkeytype treats it like normal typing.

Before opening a PR, my plan is to block any “bulk insert” at the input layer: listen to beforeinput and prevent events like insertFromPaste and any insertText where e.data.length > 1. As a fallback for devices that bypass beforeinput, we can detect sudden value jumps in input and revert. This should reliably disable clipboard pastes across mobile keyboards without relying on OS paste events.

Arjav1512 avatar Jan 16 '26 14:01 Arjav1512

I can reproduce this on mobile (Gboard / One UI). It looks like clipboard insertion often doesn’t trigger a native paste event, so Monkeytype treats it like normal typing.

Before opening a PR, my plan is to block any “bulk insert” at the input layer: listen to beforeinput and prevent events like insertFromPaste and any insertText where e.data.length > 1. As a fallback for devices that bypass beforeinput, we can detect sudden value jumps in input and revert. This should reliably disable clipboard pastes across mobile keyboards without relying on OS paste events.

I don't know why the monkeytype has been designed in such a way to accept burst insert as input so will have to look and discuss about it, so its better not to jump to PR right now

Aaryan-Dadu avatar Jan 16 '26 16:01 Aaryan-Dadu

I can reproduce this on mobile (Gboard / One UI). It looks like clipboard insertion often doesn’t trigger a native paste event, so Monkeytype treats it like normal typing. Before opening a PR, my plan is to block any “bulk insert” at the input layer: listen to beforeinput and prevent events like insertFromPaste and any insertText where e.data.length > 1. As a fallback for devices that bypass beforeinput, we can detect sudden value jumps in input and revert. This should reliably disable clipboard pastes across mobile keyboards without relying on OS paste events.

I don't know why the monkeytype has been designed in such a way to accept burst insert as input so will have to look and discuss about it, so its better not to jump to PR right now

Makes sense. I won’t jump into a PR yet. If you decide burst inserts should not count as normal input, I am happy to help with an approach that blocks beforeinput paste-type inserts and adds a small fallback for mobile keyboards that bypass native paste events. Just let me know what direction you want to take and I can adjust accordingly.

Arjav1512 avatar Jan 16 '26 19:01 Arjav1512

I would probably guess Android simulates each keypress instead of sending a paste event. Can you test on https://events.monkeytype.com/ ?

Miodec avatar Jan 19 '26 11:01 Miodec

I would probably guess Android simulates each keypress instead of sending a paste event. Can you test on https://events.monkeytype.com/ ?

From this I don't think android simulates each keypress if it would have then multiple entries for each character of "pasted" should have come, right?

Aaryan-Dadu avatar Jan 19 '26 12:01 Aaryan-Dadu

I would probably guess Android simulates each keypress instead of sending a paste event. Can you test on https://events.monkeytype.com/ ?

From this I don't think android simulates each keypress if it would have then multiple entries for each character of "pasted" should have come, right?

Looks like it simulates the whole word incoming at once, but its using the wrong event type - it should be insertFromPaste. Looks like, as usual, Android is being different for the sake of it. Not sure if this is fixable without affecting other things.

Image

Miodec avatar Jan 19 '26 12:01 Miodec

But if it would have been Android specific I don't think it would be reproducible in iOS but it is as I have shown in the video provided in the Steps to Reproduce section of this issue. This is the result for iPhone 14 iOS version 18.6.2 Browser Safari using Google's GBoard


Some research revealed this to me which hints that these operations are at IME level

According to ChatGPT interaction between keyboard input and browser differs here: IMEs (like Gboard) emit text commits Browser receives plain text insertion

User action (tap / swipe / paste / voice)
               ↓
        IME (keyboard app)
               ↓
        OS input system
               ↓
             Browser
               ↓
       DOM input events

So yeah fixing it might affect others as still the only solution I could think of is limiting the max character insertion to 1 per 'insertText' But also if we will leave it unfixed, this bug can be exploited in some manner by others affecting the overall stats

Aaryan-Dadu avatar Jan 19 '26 14:01 Aaryan-Dadu

But if it would have been Android specific I don't think it would be reproducible in iOS but it is as I have shown in the video provided in the Steps to Reproduce section of this issue. This is the result for iPhone 14 iOS version 18.6.2 Browser Safari using Google's GBoard

GBoard issue then.

So yeah fixing it might affect others as still the only solution I could think of is limiting the max character insertion to 1 per 'insertText' But also if we will leave it unfixed, this bug can be exploited in some manner by others affecting the overall stats

It can be exploited because with keydown and keyup events missing, anticheat will be triggered.

So yeah, nothing that can be done on my side if GBoard is simply not sending the correct event type as it should. The acual insertFromPaste event is already blocked in the input system.

Miodec avatar Jan 19 '26 14:01 Miodec