Re-enabling the browser right click
Wed 19th Oct 16
Update July 21st 2025
I've just come to use this and found a new way the context menu is being blocked, so here is a new function that helps to give you the context menu back:
c = getEventListeners(document).contextmenu.length;
for (let i = 0; i < c; i++) {
document.removeEventListener("contextmenu",getEventListeners(document).contextmenu[0].listener, false);
}
This is based on reading the following article which explains how to disable the context menu:
How to Disable Right-Click in Browsers
It is based around the following bit if JavaScript:
document.addEventListener('contextmenu', event => {
event.preventDefault();
});
What my snippet above does is to run through all the event listeners that have been added to the context menu and remove them. If there are multiple and some are doing extra things that are useful, then this may mess things up, but at least it will give you a place to start in trying to get the normal context menu back.
I've also added a Burp match and replace rule to replace event.preventDefault()
with true
as a quick and dirty way to prevent the listener being added in the first place.
Original
I've spent the day testing an app which disables the right click context menu, this makes testing tricky so I found the following one liner which I could drop into the browser console to re-enable it for me:
var ele=document.getElementsByTagName("*");for (var id=0;id<ele.length;++id) {ele[id].oncontextmenu=null;};document.oncontextmenu=null;window.oncontextmenu=null;
To use this in Chrome or Firefox, simply hit F12 to bring up the built in console and paste it in.
Or, as just suggested by Jason, you can put this into a bookmark like this:
javascript:(function(){var ele=document.getElementsByTagName("*");for (var id=0;id<ele.length;++id) {ele[id].oncontextmenu=null;};document.oncontextmenu=null;window.oncontextmenu=null;})();
I also found that adding the following entry to the Burp 'Match and Replace' feature would stop the code that disabled it before it even reached the browser:
This may not work in every app and will probably break apps which disable the menu in some areas but add custom menus in others, but it worked for me and so I'm putting it here as a reference for when I come back to this app. It also won't work for sites which trap the onmousedown event, for those, just swap this event with oncontextmenu and run it again.