Testing HTML5 offline manifest on tomcat localhost - html

I am trying to test offline feature of my HTML5 / Java application. I can imagine 2 ways to simulate that locally.
I turn of the wi-fi / internet of my laptop. But localhost 0 127.0.0.1 doesn't have anything to do with internet and it still keeps serving my request.
I stop the tomcat. In this case I get the standard browser error page (Unable to connect error message).
How could I test this on my local tomcat?

You could try disabling your network adapter. That would probably do it.
Instructions for Windows
Instructions for Linux

Related

Self signed certificate for communication between local Win10 native app and web app

Background: I have a web app that is accessed via Chrome on a Windows 10 machine.
I also have a native Win10 application installed on the device. The web app sends data to the Win10 application via a local web service running on the machine in IISExpress.
To allow for HTTPS communication on port 44300, I've created a self-signed certificate via PowerShell:
New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My" -NotAfter (Get-Date).AddMonths(60)
And then imported it to 'Local Computer\Trusted Root Certificates\Certificates'
From within the web app I send a command to the win10 app that looks something like this:
https://localhost:44300/CMTService.svc/JumpToAssignment?Param=Key=418584577
The win10 app is polling for these requests and picks up the message.
Issue:
Different versions of Chrome behave differently with the acceptance of the self-signed certificate. For instance versions 62, 64 and 75 all accept the certificate and allow for communication with the web service. But other versions of Chrome like 76 and 78 block communication. The Security tab in the Chrome DevTools shows https://localhost:44300 as "Unknown / cancelled" and my requests fail with ERR_SSL_CLIENT_AUTH_CERT_NEEDED. Whereas in working versions of Chrome my URL shows under "Secure origins". The only thing that I change is the Chrome version to get these different results.
I've tried enabling the Chrome setting to allow for invalid certs for localhost (chrome://flags/#allow-insecure-localhost). This temporarily works, but then after closing and reopening chrome, my requests start failing again with the same error code.
If I take one of my failing URLs and paste it into a new Chrome tab, suddenly communication with my native app in my web app resumes as normal. But it only works for that session - when I close and reopen Chrome my communication is broken again.
Question:
How do I allow for communication between my Chrome v78 web app and my local native app?
ERR_SSL_CLIENT_AUTH_CERT_NEEDED means the server is asking the browser for a certificate for client authentication.
You've described how you setup server authentication, but not described how you setup client authentication.
Likely you have enabled certificates for client authentication, but have not configured the web app to send the correct client certificate or have not configured the native app to accept the correct client certificate. That's a very open ended topic to be prescriptive without knowing more about your development efforts, but you can confirm if client authentication is enabled by inspecting a packet capture. One description of the handshake is here : https://blogs.technet.microsoft.com/nettracer/2013/12/30/how-it-works-on-the-wire-iis-http-client-certificate-authentication/.
Just an update: I implemented a javascript workaround to get around my communication issues. When first loading the web app, I simply send my first communication to IIS (destined for Win10 native app) in a separate chrome browser tab. For whatever reason this allows for successful acceptance of the certificate and kick starts the communication with IIS. This is my code to send the command in a new tab and then close it:
var inst = window.open(launchWinAppURL);
if (inst != null) {
window.setTimeout(function() {
inst.close();
}, 1000);
}
This is not the most elegant solution, but it seems to work on all chrome versions, so i'm satisfied.
Is the web app only communicating with the one win10 machine? Have you installed the self-signed cert directly to the machine? I would try installing it directly to the machine and see if the later instances of chrome allow communication.

WebRTC, Camera in Chrome and https

I am developing an application that uses WebRTC and I want Chrome to use the system camera. From what I understand, the use of the camera is allowed (in the latest versions of Chrome) only from "secure locations" (https://www.chromium.org/Home/chromium-security/deprecating-powerful-features-on-insecure-origins), like localhost and 127.0.0.1.
I want to test it locally and connect to the server both from a client that resides on the same pc as the server, and from a client from another pc. In particular, the client that connects from another pc needs to connect to the server using its IP address (I am developing/testing it in an Intranet), but the client cannot use the camera because it is not calling localhost.
Is there a way to disable this constraint, so that I am able to test it in an Intranet?
If not, are there any alternatives?
try the unsafely-treat-insecure-origin-as-secure flag in Chrome:
http://peter.sh/experiments/chromium-command-line-switches/#unsafely-treat-insecure-origin-as-secure

Using getUserMedia() on insecure origins in Chrome

I am developing a webpage that uses camera. When I test in Chrome in my local network, camera doesn't work and I get warning in the console:
getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See link for more details.
In the link provided there is an instruction to set some flags in Chrome. So I tried. My command looks like this:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --unsafely-treat-insecure-origin-as-secure="192.168.0.15" --user-data-dir=c:\chrome-dev-profile
But when I run Chrome I get this message:
You are using an unsupported command-line flag: --unsafely-treat-insecure-origin-as-secure. Stability and security will suffer.
What am I doing wrong?
Is there another way I can test in local network without setting up https server? I need this just for development.
Luka,
I've run into this bug just yesterday. I have not found out how to get Chrome to honor that flag on the command line yet. But I did find a workaround that works for my case.
I'm running my web services on a Linux machine that is running an ssh server. I'm testing on windows with chrome, and used putty to connect to the linux box from windows and then created a "local port forward" to make my remote linux box's ipaddress:port appear on localhost:port on windows. Depending on your platform this workaround may work for you. This approach isn't too cumbersome if you only have a few ports to forward.
In my particular case my setting for putty looked like
L8080 localhost:8080
To see more about port forwarding and ssh see: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding

How does chrome know when a server becomes available?

Try these steps:
Find or create a web server (Apache, Node.js, ...) that you can control
Find or create a resource to be served by said web server
Shutdown web server
Try to access a resource at that server's address in Chrome
Notice: ERR_CONNECTION_REFUSED page is shown
Start web server
Notice: Chrome automatically reloads the request.
I have two questions:
How does Chrome accomplish this? Is it just repetitively polling the server somehow?
How could I investigate this myself?
I've tried a few different google searches, but all I can find are support forums for chrome not connecting or pages being unavailable.

HTML 5 - Testing Offline Cache with localhost

My HTML 5 app is deployed on Tomcat locally, how can I test offline access?
Here's the detailed description:
I've a very simple JSP-based web app wherein I'm trying to test HTML 5 offline cache.
This is how my JSP page looks like (code snippet):
<!doctype html>
<html lang="en" manifest="example.appcache">
And, this is the manifest file:
# Resources that require the user to be online.
NETWORK:
/jsp/date.jsp
FALLBACK:
/jsp/date.jsp /jsp/staticDate.html
The app is deployed on Tomcat 6. I can very well access the date.jsp page when Tomcat is running and I do see the FF popup asking my permission to store data locally. How can i test offline page access? I stopped Tomcat but I see the standard browser error page (Unable to connect error message).
Thanks
JJ
staticDate.html is served by Tomcat as well. So you need to keep Tomcat running, but after the browser has cached the website, disable the servlet for date.jsp.
You're doing it wrong. HTML5 offline is for when your internet connection is down, not when the server is down. If you have an internet connection on your computer, then it will try to hit the server, find out Tomcat isn't running, and return a 404 or 503 error.
If your computer's internet connection is down, then the browser should recognize that you have no internet connectivity and then attempt the fallback.
This also assumes you've coded everything correctly and are using an HTML5 browser.
To test, I would suggest disabling your PC/Mac's internet connection.