How to re-enable right click so that I can inspect HTML elements in Chrome?
JavascriptGoogle ChromeJavascript Problem Overview
I am looking at a web page which has overwritten the right-click button so to display its own popup HTML element.
This prevents me from using Chrome Developer Tools to inspect elements.
Does anybody know a JavaScript snippet I could inject from the Chrome Console to re-enable the right-click?
I am okay to break the existing 'right-click' functionality, so to be able to inspect the HTML elements easily.
Javascript Solutions
Solution 1 - Javascript
If they have just changed the oncontextmenu
handler (which is the most straightforward way to do it), then you can remove their override thus:
window.oncontextmenu = null;
Otherwise, if it is attached to individual elements, you can get all the page's elements, and then remove the handler on each one:
var elements = document.getElementsByTagName("*");
for(var id = 0; id < elements.length; ++id) { elements[id].oncontextmenu = null; }
Or, it seems you can turn off such scripts; via"">https://chrome.google.com/webstore/detail/allow-right-click/hompjdfbfmmmgflfjdlnkohcplmboaeo?hl=en">via an extension in Chrome or an http://www.wikihow.com/Disable-%22No-Right-Click%22-Scripts-in-Firefox">option in Firefox - in the advanced box for javascript options, switch off 'Disable or replace context menus'.
Solution 2 - Javascript
Tested in Chrome 60.0.3112.78.
Some of the above methods work, but the easiest in my opinion is:
-
Open dev tools (Shift+Control+i).
-
Select the "Elements" tab, and then the "Event Listeners" tab.
-
Hover over the elements/listener. A "Remove" button will show up.
-
Click "Remove".
E.g. see photo.
Solution 3 - Javascript
This bookmarlet works in Google sites/Youtube as of Aug 2019 (tested in Chrome and Firefox):
function enableContextMenu(aggressive = false) {
void(document.ondragstart=null);
void(document.onselectstart=null);
void(document.onclick=null);
void(document.onmousedown=null);
void(document.onmouseup=null);
void(document.body.oncontextmenu=null);
enableRightClickLight(document);
if (aggressive) {
enableRightClick(document);
removeContextMenuOnAll("body");
removeContextMenuOnAll("img");
removeContextMenuOnAll("td");
} }
function removeContextMenuOnAll(tagName) {
var elements = document.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++) {
enableRightClick(elements[i]);
}
}
function enableRightClickLight(el) {
el || (el = document);
el.addEventListener("contextmenu", bringBackDefault, true);
}
function enableRightClick(el) {
el || (el = document);
el.addEventListener("contextmenu", bringBackDefault, true);
el.addEventListener("dragstart", bringBackDefault, true);
el.addEventListener("selectstart", bringBackDefault, true);
el.addEventListener("click", bringBackDefault, true);
el.addEventListener("mousedown", bringBackDefault, true);
el.addEventListener("mouseup", bringBackDefault, true);
}
function restoreRightClick(el) {
el || (el = document);
el.removeEventListener("contextmenu", bringBackDefault, true);
el.removeEventListener("dragstart", bringBackDefault, true);
el.removeEventListener("selectstart", bringBackDefault, true);
el.removeEventListener("click", bringBackDefault, true);
el.removeEventListener("mousedown", bringBackDefault, true);
el.removeEventListener("mouseup", bringBackDefault, true);
}
function bringBackDefault(event) {
event.returnValue = true;
(typeof event.stopPropagation === 'function') &&
event.stopPropagation();
(typeof event.cancelBubble === 'function') &&
event.cancelBubble();
}
enableContextMenu();
For peskier sites, set/pass aggressive to true (this will disable most event handlers and hence disable interaction with the page):
function enableContextMenu(aggressive = true) {
void(document.ondragstart=null);
void(document.onselectstart=null);
void(document.onclick=null);
void(document.onmousedown=null);
void(document.onmouseup=null);
void(document.body.oncontextmenu=null);
enableRightClickLight(document);
if (aggressive) {
enableRightClick(document);
removeContextMenuOnAll("body");
removeContextMenuOnAll("img");
removeContextMenuOnAll("td");
}
}
function removeContextMenuOnAll(tagName) {
var elements = document.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++) { enableRightClick(elements[i]);
}
}
function enableRightClickLight(el) {
el || (el = document);
el.addEventListener("contextmenu", bringBackDefault, true);
}
function enableRightClick(el) {
el || (el = document);
el.addEventListener("contextmenu", bringBackDefault, true);
el.addEventListener("dragstart", bringBackDefault, true);
el.addEventListener("selectstart", bringBackDefault, true);
el.addEventListener("click", bringBackDefault, true);
el.addEventListener("mousedown", bringBackDefault, true);
el.addEventListener("mouseup", bringBackDefault, true);
}
function restoreRightClick(el) {
el || (el = document);
el.removeEventListener("contextmenu", bringBackDefault, true);
el.removeEventListener("dragstart", bringBackDefault, true);
el.removeEventListener("selectstart", bringBackDefault, true);
el.removeEventListener("click", bringBackDefault, true);
el.removeEventListener("mousedown", bringBackDefault, true);
el.removeEventListener("mouseup", bringBackDefault, true);
}
function bringBackDefault(event) {
event.returnValue = true;
(typeof event.stopPropagation === 'function') &&
event.stopPropagation();
(typeof event.cancelBubble === 'function') &&
event.cancelBubble();
}
enableContextMenu();
Solution 4 - Javascript
I built upon @Chema solution and added resetting pointer-events
and user-select
. If they are set to none
for an image, right-clicking it does not invoke the context menu for the image with options to view or save it.
javascript:function enableContextMenu(aggressive = true) { void(document.ondragstart=null); void(document.onselectstart=null); void(document.onclick=null); void(document.onmousedown=null); void(document.onmouseup=null); void(document.body.oncontextmenu=null); enableRightClickLight(document); if (aggressive) { enableRightClick(document); removeContextMenuOnAll('body'); removeContextMenuOnAll('img'); removeContextMenuOnAll('td'); } } function removeContextMenuOnAll(tagName) { var elements = document.getElementsByTagName(tagName); for (var i = 0; i < elements.length; i++) { enableRightClick(elements[i]); enablePointerEvents(elements[i]); } } function enableRightClickLight(el) { el || (el = document); el.addEventListener('contextmenu', bringBackDefault, true); } function enableRightClick(el) { el || (el = document); el.addEventListener('contextmenu', bringBackDefault, true); el.addEventListener('dragstart', bringBackDefault, true); el.addEventListener('selectstart', bringBackDefault, true); el.addEventListener('click', bringBackDefault, true); el.addEventListener('mousedown', bringBackDefault, true); el.addEventListener('mouseup', bringBackDefault, true); } function restoreRightClick(el) { el || (el = document); el.removeEventListener('contextmenu', bringBackDefault, true); el.removeEventListener('dragstart', bringBackDefault, true); el.removeEventListener('selectstart', bringBackDefault, true); el.removeEventListener('click', bringBackDefault, true); el.removeEventListener('mousedown', bringBackDefault, true); el.removeEventListener('mouseup', bringBackDefault, true); } function bringBackDefault(event) { event.returnValue = true; (typeof event.stopPropagation === 'function') && event.stopPropagation(); (typeof event.cancelBubble === 'function') && event.cancelBubble(); } function enablePointerEvents(el) { if (!el) return; el.style.pointerEvents='auto'; el.style.webkitTouchCallout='default'; el.style.webkitUserSelect='auto'; el.style.MozUserSelect='auto'; el.style.msUserSelect='auto'; el.style.userSelect='auto'; enablePointerEvents(el.parentElement); } enableContextMenu();
Solution 5 - Javascript
Easiest thing to do is open the dev tools by pressing Cmd + Opt + I (Mac) or F12 (PC). You can then use the search (magnifying glass, top left on the dev tools toolbar) to select the element.
Solution 6 - Javascript
you can use following code for re-enable mouse right click.
document.oncontextmenu = function(){}
and you can use shortcut key (Ctrl+Shift+i) to open inspect elements in chrome in windows OS.
Solution 7 - Javascript
Another possible way, when the blocking function is made with jquery, use:
$(document).unbind();
It will clear all the onmousedown and contextmenu events attributed dynamically, that can't be erased with document.contextmenu=null; etc.
Solution 8 - Javascript
You could use javascript:void(document.oncontextmenu=null);
open Browser console and run the code above. It will turn off blockin' of mouse right button
Solution 9 - Javascript
Hi i have a shorter version. this does same as a best answer. (it works on chrome 74.03)
document.querySelectorAll('*').forEach(e => e.oncontextmenu = null)
Solution 10 - Javascript
On the very left of the Chrome Developer Tools toolbar there is a button that lets you select an item to inspect regardless of context menu handlers. It looks like a square with arrow pointing to the center.
Solution 11 - Javascript
Disabling the "SETTINGS > PRIVACY > don´t allow JavaScript" in Chrome will enable the right click function and allow the Firebug Console to work; but will also disable all the other JavaScript codes.
The right way to do this is to disable only the specific JavaScript; looking for any of the following lines of code:
- Function disableclick
- Function click … return false;
- body oncontextmenu="return false;"
Solution 12 - Javascript
I just visited this site and it really bugged me,
apparently there are a couple ways to disable the mouse click:
<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
if(event.button==2)
{
alert(status);
return false;
}
}
</script>
and
<body oncontextmenu="return false">
...
in this case what you will have to do in the dev tools is :
document.removeEventListener("onmousedown",disableclick);
document.oncontextmenu = function(){}
2)
using flash as a content wrapper - no solution here except taking a screenshot
some sites want to prevent downloading images via right click -> save image as
so what they do is put this:
<div style="background-image: url(YourImage.jpg);">
<img src="transparent.gif"/>
</div>
which is a transparent image spreding on the full width and height of the screen all you need to do is go to the elements inspector and find the div and delete it.
In my case #1 did the trick
Solution 13 - Javascript
The way I solved this was delete the event listeners on the page. After I did that, I was able to copy the text and paste it in to my processor of choice.
Solution 14 - Javascript
Open inspect mode before navigating to the page. It worked.hehe
Solution 15 - Javascript
If none of the other comments works, just do, open console line command and type:
document.oncontextmenu = null;
Solution 16 - Javascript
The easiest way I found is to open the webpage in Read mode (browser that supports read mode like Safari, Firefox etc) and then copy as usual
Solution 17 - Javascript
If the page you are on has a text or textarea input, click into this input (as if you want to enter text) then right-click and select 'Inspect element'.
Solution 18 - Javascript
Just Press F12
Go to Sources
There you will find Enable right click. Click on it.
Under this you will find web_accessible_resource.
Open it in this you will find index.js.
Press Ctrl + F and search for disabelRightClick. There you will find
var disableRightClick = false;
this line. Replace this line with
var disableRightClick = true;
Just press Ctrl + s
!! Done. Now your right click is enabled !!