Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open browser's JavaScript console programmatically?

How to open the browser's JavaScript console with JavaScript code?

if (ShowConsole() == false)
   alert('I cannot open your JavaScript console, please "
   + "use your browser\'s menu to open manually.')
else console.log('now you can see some message')

I suggest ShowConsole() function does not exist and is a product of my imagination, you need to go to menus and find the right item and click it. And do it different way in different browser. I am looking for some browser specific API to help lazy developers.

By "open" I mean make it visible, as if the user selected the corresponding menu command.

like image 976
exebook Avatar asked Feb 25 '14 04:02

exebook


People also ask

How do I open the JavaScript console in Chrome?

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).

How do I open console with code?

Use the Ctrl+` keyboard shortcut to toggle the terminal panel.


1 Answers

I cannot find any way to do this, so my impression is that this is explicitly designed as a security measure. After all, just try to go to Facebook.com and open the console. What do you see?

STOP!

This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or "hack" someone's account, it is a scam and will give them access to your Facebook account.

If it's a security risk, why give any developer the ability to open any security window for any user?

Theoretically, if this wasn't a problem, all you'd need to do is: <a href="chrome://inspect">Inspect!</a>. And Chrome even has initialization mode with a --allow-file-access-from-files parameter to allow greater developer freedom. This working would make sense to me -- If someone started chrome.exe with a flag indicating developer tools at the command line, it's quite clearly not some user who was tricked into opening their console, so, it should give us greater permissions.

Unfortunately, absolutely everything I have tried fails, and this gives me the impression that it's a hardcore security protocol for Google, and they won't be working anytime soon. The results to be exact...

  • <a href="chrome://inspect">Inspect!</a> : Console results with error...

Not allowed to load local resource: filename...

  • <a href="file://chrome://inspect">File!</a>: Redirects to about:blank#blocked.

  • C:\Program Files (x86)\Google\Chrome\Application>chrome.exe --allow-file-access-from-files : This appeared to have no effect at all.

The only real remaining possibility is: a Chrome plugin that allows href="chrome://..." links. I have searched and tried several, none have produced any desirable results. But the possibility is there! You said this was to help lazy developers -- this is what it will take to do a proper accommodation to laziness.

like image 70
HoldOffHunger Avatar answered Sep 18 '22 09:09

HoldOffHunger