We are developing a Chrome Apps-based application with NWJS version 0.13.0 Alpha, since lower versions do not support Chrome Apps. We need version 13, so we can use serial ports.
However, on Windows or Ubuntu, when I right-clicked, a menu was shown that I disabled (since it was specified that way) with the following function in all my HTML files:
<body oncontextmenu="return false"> <script language="javascript"> document.onmousedown=disableclick; function disableclick(event) { if(event.button==2) { return false; } } </script>
But on Mac OS X, we had another problem due to the user menu, after reading the format manifest, I found that on my package.json file I needed to add the attribute "no-edit-menu": false , and this menu is no longer displayed, the package.json file looks like this:
{ "main": "main.html", "name": "PAGUSS", "description": "Paguss Payment Services", "version": "0.1.0", "keywords": [ "paguss", "payment" ], "window": { "title": "Paguss", "transparent": true, "icon": "assets/images/64x64.png", "toolbar": false, "frame": true, "resizable": true, "position": "mouse", "min_width": 400, "min_height": 500, "max_width": 1200, "max_height": 800, "no-edit-menu": false }, "webkit": { "plugin": false } }
Now I tried to change the "toolbar": false, in the package.json file so that there is no toolbar there, and therefore the user cannot open devtools from there, but if they press F12 or Shift-Ctrl-J , they can still open the window devtools I also tried the following line in my above script, trying to disable the devtools window to open without success (at least on Mac OS X, where it is our priority to disable it):
if(event.button==2 || window.event.keycode==123 || (window.event.keycode==55 && window.event.keycode==58 && window.event.keycode==34)) { return false; }
I got the above key codes here for an Apple keyboard.
I am really new to Javascript coding, so some of my attempts are incorrect or close to correct.
Is there a way to disable Dev tools from opening on NWJS 13 on any OS?
Edit
I found that an error occurred in the second attempt with keyCodes.
I tried to call the script when right clicking, I changed the code as:
<script language="javascript"> document.onmousedown=disableclick; document.onkeydown=disableconsole; function disableclick(event) { if(event.button==2) { return false; } } function disableconsole(event) { if (event.keyCode==123) { return false; } } </script>
Which actually prevents the console from opening developer tools with the F12 key on Linux, however, Windows and OS X still do not work even with this update.
Edit 2
I found that there are different keyCodes for different OS, as shown in this table , so I think that I do not have a successful answer during testing on Windows and OS X because of this.