An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Supporting Browser-based Javascript and Node.js
Post Reply
cvboucher
Phidgetsian
Posts: 14
Joined: Fri Oct 22, 2021 11:29 am
Contact:

An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by cvboucher »

I'm using the JavaScript library in a Blazor Webassembly project. If I try to establish a NetworkConnection to anything but localhost I get the following error:
Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
I can allow insecure content but then I get a "Not secure" banner across the top of my app. I'm creating a PWA so I have to load the app over SSL. Are there any other options?

One thought I had... I know Phidgets.NET is a wrapper around a C library. Have you tried compiling the C library to Webassembly? I'm guessing a direct connection to USB Phidgets won't work but maybe the Phidget Network Server could work to open Phidgets.

Thanks,
Craig
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by Patrick »

Yes, we don't support secure websocket directly from our network server - you would need to proxy the websocket traffic yourself - whether this is actually feasible depends on your environment. Another option could be to run the Phidget code server-side rather than client-side, using Node.

-Patrick
cvboucher
Phidgetsian
Posts: 14
Joined: Fri Oct 22, 2021 11:29 am
Contact:

Re: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by cvboucher »

Thanks for the quick reply. We configure tablet type devices before we send them out to customers so we can install/setup other software if needed. We were planning to use the Wireless VINT Hub with digital inputs (either the DAQ1300, DAQ1301 or DAQ1400). Do you have any links on setting up a proxy for the websocket traffic and can this be done on each device?

When connecting to localhost with the NetworkConnection object, Chrome doesn't complain about the insecure websocket connection. I've never done Node and my Javascript isn't the strongest. So I was thinking of creating a BackgroundService in .Net Core that could be installed on each device, would use the native Phidget libraries and provide a web socket connection to my Blazor app.

Can the Phidget22 Webserver communicate with other Network Servers (act as a proxy)? If so, it would solve my issue; I could just install the Webserver on each device. It could also potentially provide Server Discovery to the Javascript libraries.

Thanks,
Craig
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by Patrick »

This is a tough use case with the HUB5000 as you can't change the software on it. I may need to look at how to implement secure websockets in the network server itself.
cvboucher
Phidgetsian
Posts: 14
Joined: Fri Oct 22, 2021 11:29 am
Contact:

Re: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by cvboucher »

Since web browsers don't complain if it's connecting to localhost, it wouldn't need to implement secure websockets if the Network Server/Webserver could act as a pass through (proxy?) to the HUB5000 from the machine that the browser is running on.
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Post by Patrick »

The network server itself cannot act as a proxy. You would need to configure a third party proxy such as lighttpd, nginx, etc., in which case, you could also configure it to proxy wss, and not have to run it on the same machine as the browser.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests