New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using chrome native messaging with electron #8692
Comments
Hi @johnryan, I think we're going to need more information to help. Can you link to the example code/report you're trying to get working? I am not quite sure if this would qualify as a bug, a feature request, or something else. |
@groundwater Thanks for responding, it's more just a general support request (i tried the electron slack but didn't get a response). All i'm trying to do is find a way to communicate between a chrome extension and my electron app. I ended up trying a totally different route and set up a web server running inside the main process that the chrome extension just posts to like any other service. If that seems more like a reasonable solution i'm happy to close this issue (and hopefully anyone else trying to do the same thing stumbles upon this solution). |
Sounds good @johnryan. You can also try the Electron section of discuss.atom.io for support. We're still figuring out what the best approach for community support it. For what it's worth, I use the exact same method with my electron apps. |
For the records, i successfully use an electron app with a WebExtensions add-on through native messaging using the following code. Sending message from app to add-on:
Receiving message from add-on:
|
interesting @mi-g Where does :
live in your electron application? all the examples i've seen just showed this approach in a separate JS file which still left the question of how to get that data into the running application. |
You can put that code wherever you want in the main thread, but not into a window renderer. |
@mi-g Got it, one more question i meant to ask. What do you set as the "path" of your script? in the chrome extension json (https://developer.chrome.com/extensions/nativeMessaging) ? i.e.
As far as I can tell all the scripts are compressed inside the app.asar file |
I do not use asar archiving, so far, i didn't see any true benefit for that but a few inconveniences. But even in asar format there must be an executable somewhere to be run to launch your application. If you use electron-builder to create an installer and execute this setup program, you should use the same resulting path as the one in the installed app shortcut. |
@mi-g I was trying to do the same. i am was able to launch the application with connectNative. I tried your method for receiving message. But on port.postMessage i am not receiving the data in electron main process. Is there any configuration I need to do before for this to work ? |
If the extension is able to launch the native application, then the data sent by the add-on through port.postMessage should end up in the application. Make sure your application has a proper logging mechanism that writes to a file and not to the console (that would break the native messaging protocol), then try to log any byte received by the application. |
Is there a open source example located somewhere? I'm not sure I understand completely @mi-g |
I use this method to do this。 |
@mi-g can you share your codes for the reference? I somehow cant make it work even after I follow your advice as given above? |
@deepakjha14: you can check code from the Video DownloadHelper companion app. |
@mi-g I have copied your code, but unfortunately from extension when I send message I am unable to receive it in the host program, the host does not do anything on message. Would you be kind enough to suggest me where I am making mistake if i upload my codes on github and give you the link? |
I presume you are sending the message from your extension using the native extension API right ? Make sure to check errors when calling runtime.sendNativeMessage |
@johnryan Have you solved the problem? |
@riskers as mentioned above I just ended up running a web server rather than using the native message protocol |
@mi-g the Video DownloadHelper companion app is a plain Node app though as best I can tell. I'm confused. You've managed this in Electron? I've gotten a Node application communicating via Native Messaging, but can't find a way to get an Electron application working. Do you have any ideas about doing this with Electron? @vapour can you share any details about how to do this? I'm put my code in the I've tried disabling console.log, but no luck so far. I think it's an issue with getting the Electron main process to accept If anyone has any pointers, I'd really appreciate it. I am soooo close to having this working after two solid days of tinkering. |
@slapbox yes, the Video DownloadHelper companion is a plain node app, but before this app becomes what it is now, i had in mind to make it an Electron one. As far as i remember from the tests i did, it was basically the same stdin/stdout code running from an Electron app and being runnable from a Firefox/Chrome extension. |
I thought that it was related to Electron attaching @mi-g do you have any ideas about what I should be researching to find a solution to this? I know it's a stupidly vague question, but I've exhausted pretty much every line of inquiry I can find. |
I'm afraid i don't remember doing anything special. It was 18 months ago, maybe since then, Electron has changed so that it now hijacks the standard streams making it impossible to use for native messaging :/ |
@mi-g thanks very much for your replies. As best as I can tell they haven't changed how it's handled for a couple of years, but perhaps I'm mistaken. This is my first real dive into streams and |
Hey guys, I am trying to do the exact same thing on Windows7:
Did you progress in any way ? |
@jml674 I eventually concluded it is impossible on Windows 7. I could be wrong, but that was my conclusion. |
@jml674 Would you recommend the websockets workaround? I've been googling trying to figure out how to get clean chrome extension <-> electron communication working, but based on all the threads I've scoured through so far it seems like it can't be done at the moment. I was considering implementing your workaround and had a few quick questions:
|
Extension load can succeed, but using chrome. Runtime. ConnectNative connection not only on local applications, but use the Google browser is ok. Is there a reason |
https://developer.chrome.com/extensions/nativeMessaging
I'm trying to communicate between a chrome extension and the electron process. I saw this issue #7681 but it seems to be trying do something different (loading the extension from the electron app).
I think the extension is set up properly but i'm not sure where the "path" should be pointed to. Is this something that is even possible in electron to listen via stdin and pass that information to the renderer process?
The text was updated successfully, but these errors were encountered: