How to create a simple WebSocket Server in Chrome App? - javascript

I'm trying to develop a Chrome App that will work together with a Chrome Extension that I already created, wherein the Chrome Extension will send information to the Chrome App.
For this communication I thought use the WebSocket locally, in Chrome Extension I managed to make the Client, but now I'm having difficulty in creating the Server in the Chrome App, because I wanted to make as simple as possible without having to install something beyond of the Chrome App.

Among the first Google results there is a sample app from Chrome team: Http WebSocket Server.
You've got to understand that making a server in Chrome Apps is difficult; you are given access to a raw socket, and you need to fully implement the protocol that a particular server must use. Even a HTTP server is non-trivial, WebSockets is even less so.
So: it's possible, but it's not simple unless you're using an existing library.

Just to add to the accepted answer:
There is a Chrome Extension already in the Chrome Web Store: Web Server for Chrome.
And it is opensource: GitHub Link. You can use it as a library to your Chrome App.
Cheers!

Related

Obtaining data from a chrome extension

I have a java application that can create a Socketed lan server to parse information from a website, with the main goal of collecting chat data. At first I was in a test version of that website and was able to just open a web socket in a chrome extension then save it toward the Java server. Now that I have went to the public version of the site where its actually heavily protected, the site has the Content Security Policy, that disallows the use of Web Sockets from chrome extensions. I am unsure if there is any possible way to transfer that chat data from the site to the server via google chrome extension or any other way.
I was trying to open a socket inside of the Website itself. "wOxxOm" gave me a lead that you cannot do that and I later on understood that you had to use websockets in the background.js of the chrome extension.

Communicate between remote Chrome extensions

I need to develop a Chrome extension that will be able to send messages between instances of the extension (i.e. active Chrome browsers with the extension installed around the world) very quickly (like push notifications).
I understand that the regular Chrome messaging (even the external type) only works with extensions installed on the same browser, not remote ones.
I'm looking for the best, simplest solution, that will provide quick communication between the clients. The only way I thought about is to get some server running (I don't have one, so I need to find an online service), and run a script that will continuously receive/forward data. Is that the best way? Is there a simpler solution to set up for very simple communication between the remote extension instances?

how to watch firebase traffic from desktop chrome inspector

I have a JavaScript app running in my desktop Chrome browser which is reading and writing to Firebase. I'd like to get a sense of how much traffic it uses (vs any local caching) and I figured I could just watch in the Chrome Inspector.
I'm not seeing any such traffic. I assume I need to tweak some Inspector setting, but it looks like I have everything turned on and nothing filtered.
How can I see this traffic? (For my current simple needs, I'd much rather do so in Chrome, and not have to fire up WireShark)
Firebase uses a websocket to communicate with clients. In the devtool's networking tab, filter by "WS" (websocket) and you should see the connection that Firebase is using.
There is a great extension for Chrome called 'GTM/GA Debug' that has a readout for Firebase hits. When using the extension in Chrome Dev Tools, look at the tab named GA4F (Google Analytics for Firebase). It is very helpful for debugging.

Chrome Extension w/ Serial and Page Action

Currently, I have created a Chrome App that gets data from a serial connection using the Chrome App Serial API. My goal is to inject this data into a web page. I know this is capable with Chrome Extensions, but the issue there is that Chrome Extensions aren't capable of accessing the serial data on it's own. I also would like to use an Extension instead of an App because the Chrome Apps aren't going to be supported starting this year.
The only option I could think of is to use a Chrome App to get the serial data, send the data to an Extension, and then inject the data into a web page. This is definitely not preferable though. Besides the Chrome Apps not being supported, except for Chrome OS, I wouldn't like to have to have a user download the extension and the app just to implement this.
My preferred method would to have an Extension access the serial devices. Is this possible and/or is it going to possible in the future? If not, why?
Thanks in advance!

How may a web page that is loaded via https connect to a WebSocket server running on localhost?

I'm trying to create a web page that can connect to a client-local WebSocket server. The idea is to use the JavaScript client running in the browser as kind of a proxy to enable communication between the remote web server and the locally installed client application which implements the WebSocket service.
So basially, what I'd do is load a web page from https://example.com which includes some JavaScript that opens a new WebSocket to ws://localhost:1234/context.
This works fine as long as the web page is accessed via http. As soon as https is used, however, Firefox and Internet Explorer refuse to connect and the WebSocket constructor throws an exception (SecurityError, code 18).
Now, I already found advice from Mozilla stating that https sites should only use secure (wss://) WebSockets and plain http sites should only use plain WebSockets (link). But I don't really see the security issue when connecting to localhost from within an https context. Besides, this works like a charm for Chrome, Opera and Safari.
So the actual question is: Is there any way to work around this issue? Like introducing a non-https context inside the web page or something similar to get all browsers to connect to ws://localhost from within a https-delivered web page?
Thanks a lot in advance! I'm not exactly a web developer so this kind of browser-specific behaviour isn't really in my fields of expertise :)
You have to accept the cert first.
You can do this by simply going to https://localhost:1234/context, in your case. Once that's done, you can use the wss URL in your question.

Categories

Resources