Windows Store App xhr to localhost fails - javascript

I have a Win Store App app which uses REST to communicate with a pinpad device attached by USB. It has it's own proprietary http server/software but it seems fairly simple.
In my dev machine and on my test machine all works as expected. However, on my tester's machine it does not. The issue is that the xhr GET is failing. It just times out and returns status 0.
A simple get using a browser is successful, as is a script run in a browser (ie, ff, ch).
I have swapped out xhr for httpClient, jquery.ajax and a direct XMLhttpRequest call - all have the same result. I have tried setting location header for CORS. Tried different formats for the address (localhost, 127.0.0.1, 192... etc). The app will happily get external content (eg google.com).
Has anyone come across something like this before? I suspect it's something to do with how a Windows Store App interacts with the lan but I don't know where else to look.

By default Windows Store apps are blocked from loopback connections to localhost. By default, Visual Studio sets up an exception when debugging and you can set one up yourself for testing or for side-loaded apps with the checknetisolation tool. If your app will be deployed from the store it cannot rely on a loopback exemption.
See Using network loopback in side-loaded Windows Store apps on MSDN:
To add a Windows Store app to the list of apps that are exempt from
the loopback firewall, run checknetisolation loopbackexempt -a
-n=<package family name> from an elevated command prompt. The package family name for a Windows Store app is available from Visual Studio
via the Package.appxmanifest editor on the packaging tab.

Related

How To Run a Flutter Web Application Offline?

I got a problematic assignment from my employers.
I was given the task of developing simple software that will run strictly on Google Chrome,
without attempting to connect to the web (Security reasons).
I know flutter development and I feel comfortable with the sdk.
How should I develop a web app that can be deployed using a usb stick?
Looks like PWA can be an option, but the documentation is lacking in detail.
The system does not have the ability to run a local web server.
The Flutter app must be able to work with JS libraries, I intend to use jsQR.
service workers and indexedDB could help you for develop offline route app and offline api.
mdn docs for service workers
I'm not sure that this will fit your particular case: you say that the system can't run a local webserver, but what if you provide the webserver along with your software?
I just discovered get_server: you can find it here. It aims to allow developers to host their own HTTP server by using only flutter, without resorting to external tools or other coding/scripting languages. It allows also (and that's the relevant part) to wrap your flutter web app and make it run on local network.
For now I only tried with a very simple example, but it seems to be working. These are the steps I took:
create a new flutter project: since I needed the webserver to run on Windows, I had to get flutter ready for that (see here for help)
add get_server to the new pubspec.yaml
run flutter build web on your flutter web project, and copy the build/web output
folder in the root folder of the new project (I renamed the folder while copying since flutter might change the content of the web folder)
delete all the content of lib/main.dart
paste this (this the actual content of main.dart)
import 'package:get_server/get_server.dart' as gs;
void main() {
gs.runApp(
gs.GetServerApp(home: gs.FolderWidget('folderName')),
);
}
folderName is the name of the renamed folder containing the flutter web app build.
I ran this on Windows 'device' from AndroidStudio, and my original flutter web app was reachable at localhost:8080 (for now I just used the default options of get_server). I also got the webserver (empty) GUI as a white window: I guess that can be useful for some information regarding the server itself, although, if that windows closes, localhost:8080 becomes unavailable.
But, once released, you should be able to just run the executable from the USB stick, and then connect to it with Chrome.
PS: after some time using GetServer, I had to switch to other packages because of not-so-good docs and support. Now I'm using shelf, but also Alfred is a notable mention.

Find a specific server on the local network

If I have a Node.js app running on a machine on the LAN that runs a web server (Fastify) and it is configured to be accessible to all devices on the LAN, how could I use JavaScript in the browser on another machine to detect that server on the LAN?
Example: On a NAS connected to my router, I run a Docker container that creates a HTTP API at the address 192.168.1.28:3000. I can manually type this into any browser on the LAN and it will access the Docker container. How can I use JavaScript to detect the existence of this server without knowing its address?
You can't.
While there are protocols for announcing the presence of a service on a network, none are supported by JS running in a webpage.
Browser extensions (such as Bonjour Browser and the poorly reviewed Railduino Zeroconf-Lookup) are possible, but since you didn't mention writing a browser extension I'll assume they aren't an option.
There's things like WebRTC but unless your device advertises that you're out of luck.
This is by design.
Can you imagine if an arbitrary web page could scan your local network and report back to some arbitrary server what it discovers?

Turn off the https requirement for https gated web APIs in Chrome and Firefox

Many modern Web APIs are gated by the browser to be HTTPS only. This is good for users but can make developing painful. During development I'd like to be able to turn off that requirement just for testing.
Is there a flag I can set (about:config in firefox, about:flags in chrome) or a command line parameter I can pass in to turn off that requirement so I can test without having to setup https certs and add them to the browser?
Note: I understand the https requirement is dropped for localhost but I'm often hosting on one machine (like a laptop) and testing on another (like an Android device) or a different desktop. I know I can generate a local cert and run a server that supports https. I then have to deal with security warnings on the browsers (invalid cert) and/or add the private certs to all the devices OR I have to register a domain solely for the purpose of getting a valid cert via letsencrypt. For my own dev I'd just like to temporarily turn off that check in the browser if possible. Of course what I actually serve to users will be https but during dev if I could turn off that requirement things would be so much easier.
In my particular case I'm trying to use WebXR so dev happens on my laptop but actual testing happens on an Android device where the page is served from my laptop.
One solution suggested here is to use Chrome's port forwarding
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/local-server
That works for Chrome desktop to Android
On your desktop you tell desktop chrome what site at what port to forward to your android device at another port. That site can be a server on the internet or a server running locally on your desktop. On the android device you can then access that site at http://localhost:<port-you-specified>. https requirements are dropped for locahost host so you can now use the APIs that were restricted otherwise.
Chrome has a developer setting Insecure origins treated as secure in chrome://flags/, this is a text field where you can add a list of origins treated as secure for development purposes. (Via https://github.com/immersive-web/webxr/issues/60)

Javascript : Run client side EXE by CHROME [duplicate]

My requirement is to launch my installed application from chrome browser if it is installed on client machine, If not installed then I wanted to start download. What is best recommended solution for chrome?
So fare i tried following
used NPAPI, but due to deprecation of NPAPI by chrome I can't use.
Checked PNacl and Pepper API both API not providing access to local file system to launch an application. They just port my C/C++ code in browser and run it in browser environment with sandbox restrictions.
Is it true only option i have is to use native messaging? Or is there any other option for simple task to launch my application from our url,
Regarding “Native Messaging”
Do users need to install my extension
Do i need to add my extension to chrome store
How to deal with Registry permissions for non admin users
Can i install extension to chrome along with my app installation
Note :- Found some providers use “External Protocol Request” to launch application but there are no enough resources where can i found more about this
Thanks and Regards,
Pravin
For what its worth,
see here - http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/nativeMessaging/
the README indicates that Native Messaging can now be added even by non-Admins.
But it appears Native Messaging will only work for Extensions: "Extensions can exchange messages with native applications(...)" and I dont imagine you can expect all of your users to do that.
To open it if it's installed you just need to register your application (at the OS level, so the details will vary by OS; you don't say what OS you are targeting) as a handler for some specific scheme, then have your page open that scheme. That's the same flow that causes mailto: links to open a user's mail client, for instance.
If you have a chrome app, you can use inline install: https://developer.chrome.com/webstore/inline_installation

How to check the version of our software from a browser?

We have a legacy software package made for native Windows. I'm writing a system to automate installing updates. One of the options is for the client to visit a web page, and from that web page, check for updates to their installation. There are two ways of identifying the software version: either reading a particular EXE file and looking at its file version, or reading the registry for our software (actually the third way is reading from their SQL Server database but that's obviously out of the question). Either of these methods would work, but I have no idea how to do it from javascript in a browser.
I'm sure there is some security, but I have seen other systems do this, so I'm sure it's possible. In general, the web page can check the client's computer for existence of certain software, and if it exists, check for the version. How can I do this from Javascript?
In MaVRoSCy's comment above: "only in IE this is possible with some ActiveX help, except if you run a dedicated local server just to serve this functionality". This actually fits perfectly, because each client computer already has a Windows Service running in the background at all times.
A simple HTTP server can be added into this client service listening on a universal non-common port number such as 16580. This HTTP server can handle requests like /currentversion which returns the current application version.
The javascript on the web page (hosted elsewhere but viewed on that client's browser) calls http://127.0.0.1:16580/currentversion to obtain the latest version.
One of the options is for the client to visit a web page, and from that web page, check for updates to their installation
Bad idea and wrong methodology
Checker|Updater have to be embedded into app
Checker have to (on start|on demand|whatever)
identify build of local app (any usable way)
Get && parse external permanent URL with data of Latest Existing Build (at least version and URL of Build)
Inform, if needed, about new version and|or download|update core, if requested by user|configuration

Categories