HTTP Server in Chrome Packaged App using Sockets API - google-chrome

I am trying to get a simple web page server from within a Google Chrome Packaged App. There is already a UDP server running within the app and working without any problems.
I am starting the socket.listen on 0.0.0.0:8080 and copying most of the code from
https://github.com/GoogleChrome/chrome-app-samples/tree/master/webserver
. The same issue is replicated in the sample app.
What I am doing is accepting the request and sending a single HTML file to all requests which have some data in the request (request.data.length > 0). The flow of the app is similar to the sample app with near-equivalent functions.
To test this I am using Socket Test 3.0 (from SourceForge). Creating a socket to 127.0.0.1:8080 and sending it GET / HTTP/1.1 as the content. As intended the Chrome App responds with the html file and correct headers. I can repeat this multiple times without restarting the App. The problem arises when the App is sent a request through Chrome. On first look it works as intended, but then it Time Out on refresh. This is also replicated in the sample app.
On debugging I found that every thing was being handles. The write socket being destroyed and a socket.accept(serverSocket, ...) being issued. I also made sure that it was done inside the callback function of the socket.write. The first request as intended is for the page requested (GET / HTTP/1.1 for localhost:8080). Second was for favicon.ico as GET /favicon.ico HTTP/1.1. And then a third connection with none in data (which is then ignored and socket destroyed). Unlike in the SocketTest where every request was answered back.
I have created a video showing the screencast while reproducing the error on YouTube. Also the repo for the project that I'm working on is at GitHub.

I had the same issues with Google's sample web server. I wrote a more robust socket server app that does not hang. The source is on GitHub at https://github.com/kzahel/web-server-chrome and you can install it from the Chrome web store at https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

Related

Chrome. Remote debugging from connected Android Device: CORS issue

I have a SPA running on my localhost:3000 and my ASP.NET Core 3.1 Web API running on localhost:44372.
I'm trying to debug the SPA from my connected Android Device. I connected the device, did port forwarding, everything is well, SPA gets opened, but then it does a request to Web API and receives CORS error. When I check network tab I see that the origin is https://localhost:3000, which is correct. Does chrome remote debugging mode somehow replace the origin, because everything works well if I open the SPA locally?
I tried to debug Web API project with custom middleware, but I'm unable to hit the breaking point: seems like it returns CORS error before pipeline even started.
Here are my CORS configs in Web API:
builder.UseCors(x => x
.WithOrigins("https://localhost:3000", "http://localhost:3000")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials())
UPDATE
The CORS errors:
UPDATE 2
I also forwarded the port 44372 which I have the Web API on and the error changed to: net::ERR_CERT_AUTHORITY_INVALID. Is this an issue with the chrome on android? I'm not quite sure how to address it. The issue seems to be with the Web API server certificate, because SPA gets loaded properly.
I managed to solve the issue by opening https://localhost:44372 on the Device. There I got a security warning, but when I chose "proceed to localhost (unsafe)" I was able to reach Web API. Then https://localhost:3000 started working well.

Recording Controller in Jmeter not recording in a localhost web server

I'm currently testing my application using phpmyadmin as my local web server.
Here's the steps I've taken so far:
In the Test Plan, I added a Thread Group, an HTTP Request Defaults and Recording Controller.
In the Workbench, I added a HTTP(s) Test Script Recorder, and a View Results Tree.
I already removed the contents in the No proxy for field in my browser, after removing that, the View Results Tree is working and is recording the pages I've navigate in my application.
My problems and questions are:
The Recording Controller is not recording the pages I navigated.
What did I do wrong?
Is Recording Controller not applicable for localhost web server testing?
I hope that someone may help me with this. Thank you.
Check in your browser configuration that localhost is not excluded from proxy managed urls.
Also be aware that you shoud use the Recording Template.
In Menu, select File > Templates > Recording.
See:
http://www.ubik-ingenierie.com/blog/templates-or-how-to-speed-up-your-tests-scripting-with-jmeter/
Also please check if you are using correct path for recording in HTTP(s) Test Script Recorder ->Recording controller, also port number should same on HTTP(s) Test Script Recorder and browser proxy.

Sending javascript code to a chrome app via the remote debug protocol

In the context of a unit test I need to send some code to the console of a chrome app I am developing. It's clear that I can do that from the chrome.debug API, but is there a way to do that from outside the browser?
Yes, there is a way; if you can do something with chrome.debug you can do so with remote debugging.
You need to enable remote debugging with command line switches; you can then connect to Chrome with a debugger client instance.
Google lists some existing debugger clients, and you can implement your own by following the debugger protocol (which works over HTTP+WebSockets).
The procedure for a debugger client is to request /json from the debugger port over HTTP, which lists all possible debug targets; the client then connects to the WebSocket associated with that target to work with it.

how html5 apache works first time

I have created one HTML5 web app which works in offline mode.I load it first time form server and then when server is off it works perfectly.Webapp url is http://localhost/index.html
Now , if I try to load that webapp first time on any new machine then how can it resolve the localhost url.I have all the resources bundled with webapp.
In this case server is off and browser is not able to locate url http://localhost/index.html
Any idea if webapp can work in offline mode , even if its not connected to server ever.
What you are doing and expecting seems to make sense. It would be smart to check the console in the Chrome Developer tools. Something along the lines of the following should be shown:
You might be serving the manifest file with the wrong content type (should be text/cache-manifest) or the fact that you're working on localhost might somehow interfere (dunno).

having problems integrating Kaazing with my website: Unable to post message to X. Recipient has origin Y

I keep getting the error trying to integrate Kaazing jms version with my .net website and activemq message broker:
Unable to post message to http://www.xgateway.com:8001. Recipient has origin http://www.x.com.
When I try to build a javascript client that is hosted by my Asp .NET website trying to connect to kaazing gateway.
I know I have everything setup ok, because i can go to www.xgateway.com:8001 and i can browse all the documentation and run the demos. I have run the stock ticker demo and watch it work perfectly. so all setup seems OK.
Now the problem is, I also have my asp .net website hosted on IIS 7 on the same machine. i'm trying to build javascript clients hosted on my .net website (port 80) that connect with the kaazing gateway. But I keep getting the above cross origin error.
In my client I am referencing StompJms.js as instructed. I have activemq setup up properly and working as well as the message broker. All demos working prove everything is setup properly.
i have also taken these steps following the instructions in the documentation:
Copy the file GATEWAY_HOME/lib/client/javascript/PostMessageBridge.html and serve it from the source origin web server (http://www.example.com); for example at http://www.example.com/bridge/PostMessageBridge.html.
Note: You must ensure that the file PostMessageBridge.html is hosted on the same origin (same scheme, host, and port) as the web server.
Add the following tags (shown in lines 2 and 3) to the section of your main application page:
<head>
<meta name="kaazing:postMessageBridgeURL"
content="http://www.x.com/PostMessageBridge.html" >
.
.
.
</head>
but still get the error. What else am i missing?
Since the port numbers used by your .NET app and your kaazing websocket gateway are different, these are considered to be separate sites. Therefore, you'll need to specify cross-site-constraint for your service.
Here's a sample snippet you'll need to add to your gateway-config.xml:
<service>
<accept>ws://localhost:8001/remoteService</accept>
<connect>tcp://localhost:61613</connect>
<type>stomp.proxy</type>
<auth-constraint>
<require-role>AUTHORIZED</require-role>
</auth-constraint>
<cross-site-constraint>
<allow-origin>http://localhost:8000</allow-origin>
</cross-site-constraint>
</service>
And here you find detailed documentation on the topic.