2

I would like to add a button to my webpage, and when this button clicked, the console will open like what happens when the user click (F12) key on keyboard.

this is my try:

document.querySelector('#openConsole').addEventListener('click', () => {
    var event = document.createEvent('Event');
    event.initEvent('build', true, true);
    event.keyCode = 123; // F12 key code
    document.dispatchEvent(event);
});
<button id="openConsole">open console</button>

But it doesn't work!

Zuhair Taha
  • 2,808
  • 2
  • 35
  • 33
  • 2
    Of course it doesn't work. There's such a thing known as security. JS can't interact with a users computer and / or browser. – icecub Aug 02 '18 at 08:56

1 Answers1

2

Dev tools can't be opened programmatically as it would lead to insecurity.
Opening this would allow control which then could be exploited by injecting data for example.

DNKROZ
  • 2,634
  • 4
  • 25
  • 43