8

I want to create a TCP server and listen on it. I need access to the tab content, so I need a chrome extension. Sadly, only chrome apps can create TCP servers.

Is it a valid/good concept to create a TCP server in a chrome app and let the app communicate with an extension (is this even possible?)?

If not, what would be my alternatives? The only idea I have is to change from server model to client model and let the extension connect to an external server. This solution would be poor in my situation, so I try to avoid it as best as I can.

What I want to achieve is that I can build a chrome extension that modifies/refreshes content with remote access (nothing malicious). External programs should be able to connect to the extension (or: the app) and send their commands to it.

The Wavelength
  • 2,836
  • 2
  • 25
  • 44
  • you cannot use chrome.tabs in chrome app i guess. what you want to achieve? – Shivang MIttal Sep 08 '14 at 06:30
  • 1
    I know that. But the idea was to communicate between a chrome app and a chrome extension via port messaging. The question is: is this a good concept? What I actually want to achieve: see first post (added something). – The Wavelength Sep 08 '14 at 13:11
  • I got your point, i was dealing with the same problem earlier. what i did is that, i created a native application as an intermediate b/w my original application and chrome extension. So chrome extension use to communicate with the native application with native app messaging https://developer.chrome.com/extensions/messaging#native-messaging. then your native app will use to communicate with your external application. the approach was easy and more flexible for me. Please let me know if the idea helps @the Wavelength – Shivang MIttal Sep 08 '14 at 13:21
  • @Shiv That's massive overkill. An extension and an app can communicate directly via External Messages. – Xan Sep 08 '14 at 13:34
  • i dont know if it works in remote. – Shivang MIttal Sep 08 '14 at 13:37
  • @Xan : Can an external application communicate with chrome extension directly? please explain the way (so that all the permissions are possible like chrome.tabs etc). I thought the only solution was native messaging. – Shivang MIttal Sep 08 '14 at 13:40
  • @Shiv You misunderstand the question then. A Chrome App - not a native app - can be a TCP server, and it can talk with an extension using `(send|on)MessageExternal`. Arguably, I misunderstood what you said. – Xan Sep 08 '14 at 13:41
  • @Xan : got you.. misunderstood the question. thanks – Shivang MIttal Sep 08 '14 at 13:46
  • Right, as Xan mentioned, I meant Chrome Apps, sorry if this didn't get clear in the first post. – The Wavelength Sep 08 '14 at 15:27

1 Answers1

1

Yes it's a good idea.

1°) You should create a Chrome App Web Server (based on https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/webserver for example, or any other HTTP s)

2°) Then you should request it from any javascripted web page via XmlHttpRequest.

+++: No need for Chrome Extension. Should work with any modern browser on Windows / Mac / Linux with Chrome 33+ installed.

Supersharp
  • 29,002
  • 9
  • 92
  • 134