Search code examples
javascriptkeypresstextinputpreventdefault

bypass e.preventDefault() onkeypress


I am trying to write a userscript which creates a text input on a website, however in the website's javascript code, a function called on keypress or something else calls e.preventDefault() which prevents text input. I do not have access and cannot change that function. Is there any way to bypass that?


Solution

  • We have to register an event listener to be able to call preventDefault or stopPropagation. If the methods are called, I believe there's no way negating the effect after the default was prevented or the propagation stopped.

    The only chance would be: register you own listener before the website has a chance to register it's own. Which probably happens in a script and if you can find that, you can inject your own script before that. Then your handler would be called first and that could work for you. (you could call stopPropagation and the other listener wouldn't be called anymore)