I am making a Chrome extension for a webpage. In this webpage, I need to catch the response that the server sends when a user makes a POST request.
Currently, we are using the Observer pattern to check changes on the HTML page, but this is clumsy and it fires several times.
I need to catch that response, parse its information accordingly, and then base on it do some actions on the page's HTML by changing (adding some colors to some tables, add additional info, etc).
My issue here, is that I don't know of any JavaScript library or pure method that allows me to listen to server responses, so I can parse them.
I tried JavaScript's EventSource
, however for it to work I need to have specific code in the server and that is not an option.
Another research venue was making the request myself using an XHMLRequest
, but then I would have to have a listener on every button on the page so I could stop its default action and perform it via my code, which doesn't sound that good either.
The http.server.listen () is an inbuilt application programming interface of class Server within the http module which is used to start the server from accepting new connections. Parameters: This method accepts the following two parameters:
You can easily remove an event listener by using the removeEventListener () method. The first parameter is the type of the event (like " click " or " mousedown " or any other HTML DOM Event .) The second parameter is the function we want to call when the event occurs.
You can call like: server.listen (80) server.listen (80, '127.0.0.1') server.listen ('/tmp/server.sock') Gets the server up and listening.
You can call like: server.listen (80) server.listen (80, '127.0.0.1') server.listen ('/tmp/server.sock') Gets the server up and listening. Wraps node's listen (). Once listen () is called, this will be filled in with where the server is running. Name of the server. fs-extra contains methods that aren't included in the vanilla Node.js fs package.
How about something like this?
(function(open) {
XMLHttpRequest.prototype.open = function(m, u, a, us, p) {
this.addEventListener('readystatechange', function() {
console.log(this.response);
}, false);
open.call(this, m, u, a, us, p);
};
})(XMLHttpRequest.prototype.open)
You can override open function and then do with response whatever you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With