sindresorhus / electron-debug

Adds useful debug features to your Electron app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Context-menu fails in 0.3

seriema opened this issue · comments

Issue: I get errors in the dev tools console when activating (and deactivating) the debug view.

electron-debug v0.2.1 seems to work fine.

electron-debug v0.3.0, v0.3.1, and v0.3.2 give the same error:

Uncaught Error: No /Users/john-philipjohansson/Documents/GitHub/HipsterChat/node_modules/electron-debug/context-menu

I tried it with node 0.12.2, 4.2.1, and 5.0.0.

I reproduced it in Caprine (where I first found this module) (using node 0.12.2 and 4.2.1), but then the error message is slightly different:

Uncaught TypeError: Cannot read property 'install' of undefined

Both seem to happen in index.js activateDebugContextMenu()/deactivateDebugContextMenu() where it calls webContents.executeJavaScript() trying to require('${__dirname}/context-menu'.

Side-note: It seems that electron-localshortcut wants a higher version of node than electron-debug, which causes a warning when trying to install electron-debug. Maybe node >=4.1 is important, maybe it's not. The output is:

$ npm install electron-debug --save
npm WARN engine electron-localshortcut@0.3.1: wanted: {"node":">=4.1"} (current: {"node":"0.12.2","npm":"2.13.1"})
electron-debug@0.3.2 node_modules/electron-debug
└── electron-localshortcut@0.3.1

@seriema, could you check if /Users/john-philipjohansson/Documents/GitHub/HipsterChat/node_modules/electron-debug/context-menu.js file exists on your drive?

Regarding your side note, I think the engine requirement on local-shortcut is erroneus. Since the module is anyway running on electron it should work independently of the node version used. I've opened an issue there and I'll removed it soon. Thank you for point that out!

Anyone knows if it possible to specify electron as engine requirement?

What version of electron are you using?

Anyone knows if it possible to specify electron as engine requirement?

No, the engine field in package.json isn't even enforced in Node.js. It's just for humans.

Ok, than I merely remove it.

Just published version 0.3.2, message disappear. I noticed electron-debug has the same problem, it specify node >=0.12.0. I think we should remove it from here too, it can be confusing for users.

@seriema I reproduced the bug on caprine too.

I found the problem (at least the one on caprine).
It fail because BrowserWindow is created with node-integration:false, so require is not available
in renderer context. (Well, it is, but it appear it always return undefined).

We have to merge context-menu.js code in index.js to avoid the problem, or otherwise include it with a <script> tag. @sindresorhus any preferences between the two?

After thinkings more, it will not work anyway, since context-menu.js depends itself on use of require to create & load the context menu.

I fear our best option here is:

  • check if node-integration is disabled on window and if so just disable the feature.
  • find a way to use preload BrowserWindow option to inject a script in renderer process (this scripts always have node integration enabled). But I can't imagine a way we could control this...

As a user of electron-debug I'm not quite sure what I gain from the context-menu. If I can right-click or not in my app is a separate decision from my debugging tool, and once the debugger is open I can click the "select element" icon. So I'm trying to understand what all this is trying to add to me as a library user. Especially if you'll end up trying to hack my app somehow (injecting itself etc), since that could have any kinds of consequences. I'm super happy with just the F12 stuff. If there was some logg-file feature it might be nice, but that could easily be another module.

@seriema, my reasoning is because I, instead, find the "inspect element" feature to be useful, so I'll try to keep it, if possible.
Please note the context menu is enabled only when you open dev-tools, so it's not interfering with your app in any way if you're not debugging it.

However, I agree with you, we have to keep it simple, this is way my first purpose was to
check if node-integration is disabled on window and if so just disable the feature.

Last thing: since you receive a different error on your app and on caprine, could you confirm that in your app the error disappear if you enable node-integration?

There's a keyboard shortcut in Chrome, Cmd Shift C. Maybe that would be more in line with the rest?

Also the "select element" icon is easy to access after opening the dev tools:
screenshot 2015-11-07 20 13 16

This extra stuff is obviously tricky, and has bloated the code from 5kb to 23kb, which isn't a great trend for something I like to bundle with my app (as Caprine does). Maybe convenience features could be a separate project? Then it could add things like better error output, error detection, logging, live reload, etc.

What are you measuring? context-menu.js is 734 bytes, and index.js is 1,8 Kb...

Not sure why you're counting a few kilobytes when an Electron app weigh in a 100+ megabytes.

Uhm... maybe beacuse we do a stressfull job 😄 ?

I looked at the node_modules folder and was trying to point out the relative increase in size as a marker of how easily this will just grow to depend on more and more stuff, that themselves depend on more and more. Then the configuration comes in, and I think you know where I'm going with this.