How to stop a form from blocking paste in Safari

This is a quick blog post, mostly for my own reference.

I finally got sick of a certain government website thinking that preventing pasting passwords into certain forms was some sort of security feature, so I am documenting my workaround in Safari for stupid forms written by compliance-minded folks (the same who think that expiring passwords every 30 days leads to any kind of better security).

In Safari, select Develop > Show Javascript Console (or press ⌥⌘C, that's Option + Command + 'C')1.

Paste the following into the console and press 'Enter':

var allowPaste = function(e){
  e.stopImmediatePropagation();
  return true;
};
document.addEventListener('paste', allowPaste, true);

Now you can paste to your heart's content.

1 If you don’t see the Develop menu in the menu bar, choose Safari > Preferences, click Advanced, then select “Show Develop menu in menu bar.”

Comments

I would recommend getting StopTheMadness.

It does this for you much easier!

True, but it's a pretty heavyweight extension that does a lot more than just fix dumb paste-handling javascript.

The track record for 'popular extensions that get bought out then malwarified over time' is not great, so I'm extremely picky about any browser extension I install (right now just AdGuard and 1Password).

lol they don't understand that it's difficult to secure anything client side.

Thanks so much for this. Is there a workaround to override right click prevention? My bank prevents right click and pasting.

Thanks!

Thank you! This was brilliant. Was trying to change password on my credit card account and could not paste newly generated password from 1Password into my account.
You can paste using keyboard shortcut Ctrl+V on Windows Command ⌘+V on Mac

this does not work for me at all. definitely no develop option under safari.. I pressed the shortcut buttons didn't work either.

I got this to work by pasting in the Javascript Console but how do you save it so it always works day after day? As soon as I close Safari or go to another website it does not work and is gone from the Console.