how can i make a web socket connection in chrome console? - javascript

I'm using a website which uses Web Socket to send and get real time data. I trace it in Google Chorme and FF console and understand that after creating a web Socket use some methods in order to send and get data. Now I'm trying to imitate the procedure and manually do that! sending data which is exactly matched with the site format but I don't really know how can I make a connection and use the methods. when I traced the website I saw that some where in a code by using "this" access the connection so I couldn't find it out where the connection is created but I know all parameters of the created connection.
could anybody help me figure it out?
thanks in advance

There is not need for creating a new WebSocket connection, you can access the existing one by going to the devtools Memory tab, creating a snapshot:
Searching the snapshot for WebSocket:
Then saving the appropriate WebSocket object as a global variable (right click the object and select the Store as global variable option):

Related

MongoDB "Failed to query for documents to update ... unable to decode message length: EOF"

I'm doing a bunch (i.e. around 30) of upserts in a row and occasionally getting "Failed to query for documents to update: handshake failure: connection(etc-etc-etc.mongodb.net:27017[-10399]) unable to decode message length: EOF". Each update uniquely changes the whole document, as opposed to changing the same field(s) to one new value as with updateMany.
Is this a problem with making many separate update requests? I'm using MongoDB's Stitch service FWIW. The Stitch js API suggests that it just creates one connection, but it feels like every update is trying to create a new connection or something.
In my case I received this message when using the GO MongoDB client library. I was trying to issue a shutdown command, but apparently this can only be issued from localhost.
Run the shutdown against the admin database. When using shutdown, the connection must originate from localhost or use an authenticated connection.
I am using an authenticated connection, but I'm guessing there's some error being returned that the library isn't expecting.
I'm wagering that because the Stitch service is a MongoDB product it will be written in Go. They seem to really love Go these days :).
I doubt this will help you, but it's probably an issue with the driver.

html5 websockets closing connect when a link is clicked

I use the javascript websocket to connect to the websocket server. I use python flask framework to navigate through webpages.
my project is as below:
the route "/" renders index.html page. In this page, I create a
websocket connection.
when I receive data from the server, I navigate to different route (for instance: "/page/1")
When i click on the href link on my index.html page, i see the websocket is being closed.
I googled out and implemented 2 methods of persistent storage.
LocalStorage
Shared Web Workers
Both of them were not of any use, since, the websockets are being closed when i click on the href link. From this I think that persistent storage of websocket instance is not a solution to my problem (please correct me if i am wrong). Please suggest me the right approach to tackle my problem. Thank you in advance.
I am using the latest version of google chrome (52.0.2743.82)
The WebSocket connection only persists as long as the page it was established for is open. Loading another page closes the WebSocket, so storing a reference to the object does not help (what it references no longer exists). You need to establish a new WebSocket connection after each page load.
(For an older look into how the problems here, see http://tavendo.com/blog/post/websocket-persistent-connections/, and 10.2.3 in the HTML spec https://html.spec.whatwg.org/multipage/workers.html#shared-workers-introduction)

Pass data from chrome extension to .net app

I'm trying to send data from my chrome extension to my .net application using ajax. I'm using background script to send data. Currently i'm unable to get data at my server. I guess there's issue in setting up manifest for chrome. However, how can i post data from chrome extension?
Suggest any other alternatives if possible.
Thank you.
You can send data to the server using XHR, or use jQuery.ajax() if you prefer. The end point will be the web service you have defined on the server. Check out this example, which uses jQuery for it.
For posting data, you pass all the data you want from the client in JSON format. You can use JSON.stringify() to convert your JavasScript object to a JSON string. If your object matches an entity structure on the server, it should automatically populate it, allowing you to specify that entity as the parameter of the web method. Otherwise, you can accept an object parameter and extract the data from that.
In a Chrome extension, make sure you have the correct cross-origin permissions.
There is a specific mechanism in Chrome for communication with local applications: Native Messaging.
There is an important limitation to keep in mind: Chrome cannot talk to an already-existing process; it can only start a new one and talk over STDIO.
So you may need to have a "proxy" process that Chrome can start, which will connect (somehow, but no longer restricted in methods) to your main app and relay data.

How can I access the browser's window object from a nodejs application?

I'm trying to write a simple app to watch over files changes and automatically reload the updated code in the browser. I'm aware of the existance of livereload nodeamon and others, i just wanted to write my own. I've created the server, let it read the file i want to read, called the watcher that kills and restart the server when changes happen in the watched file. Last part: it should refresh the browser. how is this possible?
As others have explained, the browser programming environment and thus window.location.reload() is completely separate from node.js so you cannot call that directly from node.js. Server-side code runs on the server in node.js. Client-side code in the browser runs in the browser only. The two may communicate via Ajax requests or messages sent over a webSocket connection, but they can't call code in each other directly.
For a browser to refresh based on something that changes on the server, there are two basic approaches.
Javascript in the browser can regularly ask the server if it has anything new (usually with an Ajax call that passes a timestamp). If the server says there is something new since that timestamp, then the Javascript in the browser can request the new data/file. This "polling" approach is not particularly efficient because if the data doesn't change very often, then most of the requests for something new will just return that there is nothing new. It's also not friendly for battery life.
The browser can make a lasting webSocket connection to the server. Then, when the server finds that something has changed on the server, it can just directly send a notification to each connected browser informing it that there is something new. All connected clients that receive this message can then make a normal Ajax call to retrieve the new data. Or, the new info can just be directly sent to the client over the webSocket. In either case, this direct notification is generally more efficient than the "polling" solution.
With the webSocket option, you will NOT want your server to restart because that will drop all webSocket connections. I'm not sure why you're currently restarting the server when something changes, but you will have to change that to use the webSocket solution.
NodeJS does not have a window variable that represents the global namespace. Instead it has a variable called global.
There is no browser, window or URL location in NodeJS.
It's a purely server side tool.
In node.js you have process which is a node.js global object like window which is a browser global object.
For more info type process into the node.js shell.

Can you manipulate a WebSocket connection of your browser with javascript?

I'm trying to "manipulate" an existing WebSocket connection of the browser.
For example: I visit the page example.com which creates a websocket connection with my browser.
Is there any way to access this connection and send data from javascript?
If you're trying to use your own Javascript to send data on a webSocket that the webpage's Javascript opened, then you will have to "hack" into the variables of the webpage to find how/where it stores the webSocket that it opened up. It would take some sleuthing through the site's Javascript to see how practical/possible that was. There is no "standard" way that a webSocket is stored in a page that allows you to just get it from there. You'd have to get it from the existing Javascript. If it's stored inside a closure, then it may not even be possible to get it from the console.
Or, you could just open your own webSocket to the page's server from the console and do whatever you wanted to do with your own webSocket using your own Javascript from there. You don't have to use the webSocket that the page opened as long as you can see from the Javascript in the page how it opens the webSocket and anything that might need to be sent in order to initialize the webSocket properly.
I would also suggest that you observe all applicable laws, licenses and terms of service.

Categories