84

On many webpages they are blocking copy/paste using JavaScript.

Is there any way for making such inputs work as the should (e.g. enable copy/paste)?

I’m using Google Chrome.

user219095
  • 65,551
syntagma
  • 1,023

14 Answers14

106

Simply highlight the text and drag it into the text field. Try it here!

This is confirmed to work in Firefox, Chrome and Safari.

Gabriel R.
  • 2,127
54

Press F12 or open the browser developer panel and paste the following code into the console.

var allowPaste = function(e){
  e.stopImmediatePropagation();
  return true;
};
document.addEventListener('paste', allowPaste, true);
Giacomo1968
  • 58,727
23

If you're using Firefox, I found the following solution. Not sure what minimum version is required, however.

  1. Go to about:config
  2. Search for dom.event.clipboardevents.enabled
  3. Double-click it to change the value to false

This allowed me to paste immediately after changing it. I didn't even have to restart the browser.

Mirrana
  • 962
14

Here's an open source Chrome Extention

https://chrome.google.com/webstore/detail/dont-fuck-with-paste/nkgllhigpcljnhoakjkgaieabnkmgdkb

If you're interested in the code https://github.com/jswanner/DontFuckWithPaste

10

It's hacky and won't work always but a lot of the time there is just a listener set for CTRL+C / CTRL+V and you can get around it by using CTRL+INS / SHIFT+INS instead of copy / paste.

If they are doing something goofy like using flash to write an empty string to the clipboard in a loop (twitch) then you are out of luck.

Junkiebev
  • 409
4

Decide to add my solution to this (making a bookmarklet inspired from this repo and extension https://github.com/jswanner/DontFuckWithPaste) This bookmarklet will also allow copying on documents that disable that using javascript.

javascript:(function(){
  allowCopyAndPaste = function(e){ 
      e.stopImmediatePropagation(); 
      return true;
  };
  document.addEventListener('copy', allowCopyAndPaste, true);
  document.addEventListener('paste', allowCopyAndPaste, true);
  document.addEventListener('onpaste', allowCopyAndPaste, true);
})();

AllowCopyAndPaste

Legion
  • 141
2

The easiest workaround (in terms of user-friendliness) for Google Chrome would be adding Allow Copy extension.

1

There have been multiple solutions for Windows listed here. This one is for Linux desktops. The approach is the same - emulate keystrokes for the clipboard contents.

Create a shell script with the following lines and bind it to a key sequence (e.g. Strl+Super+V):

#!/bin/sh    
clip_text="$(xclip -o -sel clipboard)"
sleep 0.5
xdotool type --clearmodifiers --delay 200 "$clip_text"

Both xclip and xdotool are present in any Linux distribution repository.

1

If the block is due to the input tag having a readonly attribute, you can use the following Tampermonkey script to remove the readonly attribute from all input tags (substitute mywebsite.it with your website):

// ==UserScript==
// @name         Remove readonly attribute
// @namespace    http://tampermonkey.net/
// @version      2024-12-01
// @description  try to take over the world!
// @author       You
// @match        https://mywebsite.it/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mywebsite.it
// @grant        none
// ==/UserScript==

(function() { 'use strict';

function removeReadOnly(element) {
    element.removeAttribute("readonly");
    for (const child of element.children) {
        removeReadOnly(child);
    }
}

const inputs = document.getElementsByTagName("input");
for (const input of inputs) {
    removeReadOnly(input);
}

})();

1

You could simply disable JavaScript on the page using a simple bookmarklet. From. http://javascript.about.com/library/bldis.htm

If you create a bookmark that contains the following script as the link (or even paste this code into the address bar and press enter) then it will rip all the JavaScript off of the current page:

javascript:void(d=document);if(frames.length){alert('Script%20doesn/'t%20work%20in%20frames');}else{while((el=d.getElementsByTagName('script')).length){el[0].parentNode.removeChild(el[0]);};onerror=function(){};d.close();}

The problem of course is that while you will now be able to paste into that text box if the form used JavaScript to submit the form then that too will be broken.

Mokubai
  • 95,412
0

On Windows you can use AutoHotkey

Syntax:

::whatever::
Send [....text… Use  {enter} for line breaks]
return

Example: If you type xyz it will write the text below (as if it was written):

::xyz::
Send hi {enter} This a new line  {enter}. Another new line  {enter} whatsoever. {enter} 
return
Giacomo1968
  • 58,727
J. Does
  • 149
0

For Windows, I maintain an open-source app DevComrade which, amongst other things, simulates typing of the current clipboard text upon hitting Win+Ins. Perfect for those pesky websites and desktop apps messing with the paste functionality.

noseratio
  • 2,963
0

On Microsoft Windows, I use a voice command in Dragon NaturallySpeaking to paste text from the clipboard into input fields that block it copy-pasting:

Sub Main
    SendKeys Clipboard
    Rem originalClipboard = Clipboard
    Rem Clipboard("str(" & originalClipboard & ")")
    Rem SendKeys "originalClipboard"
    Rem Wait(1)
    Rem Clipboard(originalClipboard)
End Sub

enter image description here

I've used that solution for many years with Dragon NaturallySpeaking 12.5 + Windows 7 + mostly Chrome, it works on all websites. The only limitation is if the copied text is very long, in which case one gets the following error message:

enter image description here

I've never bothered improving the script to accept a very long text input, since fields expecting a long input text pretty much always accept copy-pasting, but that should be straightforward if needs be.

Franck Dernoncourt
  • 24,246
  • 64
  • 231
  • 400
0

https://github.com/tddschn/dont-fuck-with-paste

I made a script that uses pyautogui to simulate the pasting that works for text fields in any app, including browsers.

You can install the tool using pipx install dont-fuck-with-paste and use software like Alfred / Keyboard Maestro / Raycast to invoke the simulated pasting by running dfwp or ~/.local/bin/dfwp.

Teddy C
  • 397