最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to open browser's JavaScript console programmatically? - Stack Overflow

programmeradmin0浏览0评论

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 mand.

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 mand.

Share Improve this question edited Feb 25, 2014 at 5:07 Karthik Surianarayanan 6263 silver badges21 bronze badges asked Feb 25, 2014 at 4:46 exebookexebook 34k42 gold badges152 silver badges241 bronze badges 4
  • 4 product of my imagination nice thought – Deepak Ingole Commented Feb 25, 2014 at 4:50
  • Might be interested in stackoverflow./questions/7798748/… – Deepak Ingole Commented Feb 25, 2014 at 4:53
  • 1 Sadly, I don't think it's possible to open devtools programmatically in a normal browser. If you're making an Electron app, you can use toggleDevtools. – Brady Dowling Commented Apr 29, 2019 at 14:06
  • 3 You can't and you shouldn't either, if the user needs to see something use alert() otherwise log it to a file. Dev tools are for debugging not end user experience – Sam Stephenson Commented Jun 12, 2019 at 15:00
Add a ment  | 

1 Answer 1

Reset to default 3

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. 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 mand 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 acmodation to laziness.

发布评论

评论列表(0)

  1. 暂无评论