Here is my script (intentionally simplified):
// ==UserScript==
// @name StackOverflowExample
// @include https://stackoverflow.com/*
// @version 1
// @grant none
// ==/UserScript==
document.addEventListener('keydown', (e) => {
console.log('I print before the "e"')
conosel.log({e})
console.log('I print after the "e"')
})
When this script is loaded into my page (Stack Overflow), I see the 'I print before the "e"' get printed to console, but I don't see the 'e' or the 'I print after the "e"' get logged. Why is this?
I have tried adding things like e.preventDefault()
and that made no difference.
The puzzling thing is that this kind of thing inside the event listener still works:
document.addEventListener('keydown', (e) => {
if(e.keyCode !== 40)){
console.log('you pressed some random key')
} else {
console.log('you pressed the "UP" arrow key')
}
})
So the e
object is defined (just press any key and then 'up'). Any ideas?
Edit: seems I was wrong with the second part, (although I was so sure I saw it work on another website...)