Undisable paste on the California DMV website

Viewed 237

The CA DMV has a website that disables pasting in some non-standard way, as none of the standard techniques (setting the correct option in about:config for Firefox, extensions for Firefox or Chrome) for correcting this behavior works. When you try to paste into one of the disallowed fields, it pops up a dialog that says, "Sorry, this functionality is disabled."

  1. How is this done?

  2. How do I correct it?

2 Answers

It has already been mentioned why this happens: essentially, there are event listeners on the input elements that detect and block right-click and control key events. (Expand the snippet below to see the functions that do this.)

function whichButton(event, msg) {
  if (event.button == 2)//RIGHT CLICK
  {
    alert(msg);
  }
}

function noCTRL(e, msg) {
  var code = (document.all) ? event.keyCode : e.which;
  if (parseInt(code) == 17) //CTRL
  {
    alert(msg);
    window.event.returnValue = false;
  }
}

While the answer already mentioned (preventing keydown propagation) addresses the control key issue, it does not re-enable right-click. I would assert that the simplest solution to this issue is simply to redefine the whichButton and noCTRL functions called by the event listeners to be blank. To do this is trivial:

whichButton = noCTRL = () => {}

You could wrap this in a userscript like so:

// ==UserScript==
// @name         Reenable Paste on CA DMV
// @match        https://www.dmv.ca.gov/FIM/sps/uscfed/usc/self/account/create
// @grant        none
// ==/UserScript==

whichButton = noCTRL = () => {}

To use the userscript, you'll need to install Tampermonkey or Greasemonkey.

You can see how it's done in the source HTML - they have an inline keydown attribute:

<input class="entry-field" name="usc.form.password.new.confirm" id="password_new_confirm" value="" size="20" maxlength="20" tabindex="3" onmousedown="whichButton(event, 'Sorry, this functionality is disabled.')" onkeydown="return noCTRL(event, 'Sorry, this functionality is disabled.')" type="password" />

One option would be to write a userscript that intercepts keydown events in the capturing phase, and calls stopPropagation() so that the event doesn't capture down to the listener on the restricted fields (like the "Verify Password" and "Email Address" fields):

// ==UserScript==
// @name         Reenable Paste
// @namespace    CertainPerformance
// @version      1
// @match        https://www.dmv.ca.gov/FIM/sps/uscfed/usc/self/account/create
// @grant        none
// ==/UserScript==

document.body.addEventListener('keydown', (e) => {
  e.stopPropagation();
}, true);
Related