Turn off wss for ASP.NET Core Hot Reload functionality

Currently, I am utilizing ASP.NET Core's hot reload functionality. It attempts to establish connections with two websockets: ws and wss.

The ws connection is successful and enables hot reload to function properly. However, since my local development environment does not use HTTPS, the wss connection fails, resulting in an error message displayed in the devtools console:

Firefox can’t establish a connection to the server at wss://localhost:50005/.
WebSocket failed to connect.

This recurring issue is quite bothersome. Is there a way to configure hot reload to exclusively utilize ws?

Answer №1

It appears that there is no official solution available at the moment. I have submitted a request on the repository: PLEASE UPVOTE it.

Meanwhile, I have come up with some rather unattractive workarounds that involve patching the hot reload script.

These workarounds need to be executed before the hot reload script (

/_framework/aspnetcore-browser-refresh.js
) loads.

Temporary Workaround 1

class DummyWebSocket {
  constructor(url, protocol) { }
  addEventListener(eventName, callback) {
    if (eventName === 'close')
      callback(new ErrorEvent(''));
  }
  removeEventListener(eventName, callback) { }
}

const nativeWebSocket = window.WebSocket;
window.WebSocket = function(...args){
  if (args[0].startsWith('wss://localhost:'))
    return new DummyWebSocket(...args);
  else
    return new nativeWebSocket(...args);
};

With this workaround, only undefined is logged in the devtools console.

Note that while this reduces the noise of two red errors, it may not be foolproof and could fail if the underlying script changes.

Temporary Workaround 2

This workaround completely suppresses logging but aggressively patches console.debug.

class DummyWebSocket {
  constructor(url, protocol) { }
  addEventListener(eventName, callback) {
    if (eventName === 'close')
      callback();                                   // <----
  }
  removeEventListener(eventName, callback) { }
}

const nativeWebSocket = window.WebSocket;
window.WebSocket = function(...args){
  if (args[0].startsWith('wss://localhost:'))
    return new DummyWebSocket(...args);
  else
    return new nativeWebSocket(...args);
};

const nativeConsoleDebug = window.console.debug;    // <----
window.console.debug = function(...data) {
  if (data[0] === 'WebSocket failed to connect.')
    return;
  else
    nativeConsoleDebug(...data);
}

If you have a more effective workaround, please share it so I can accept your solution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing SVG in NextJS 13 with custom app directory: A step-by-step guide

Recently, I decided to explore the app directory and unfortunately ran into some issues. One of the main problems I encountered was with image imports. While PNG images imported without any problem, SVG images seemed to break when importing in /app. For i ...

Using React to insert a link with JSX variables

When inserting normal HTML elements with React variables in JSX, there are a few ways to go about it. One option is to use the dangerouslySetInnerHTML attribute or you can utilize a package like html-react-parser from npm. The following code demonstrates ...

Increment field(s) conditionally while also performing an upsert operation in MongoDB

I need to perform an insert/update operation (upsert) on a document. In the snippet below, there is a syntactical error, but this is what I am attempting to achieve: $inc: { {type=="profileCompletion"?"profileCompletion":"matchNotification"}: 1}, If the ...

Retrieving a single object from an array in node.js utilizing elemMatch

My goal is to extract a single object from an array of objects in a data collection using elemMatch. Here is the sample data: [ { "_id": "5ba10e24e1e9f4062801ddeb", "user": { "_id": "5b9b9097650c3414ac96bacc", "firstName": "blah", ...

Tips for accessing files following the transmission of a post request within the req.body

Encountering a problem where image uploads to an s3 bucket are not successful. The error message received is: API resolved without sending a response for /api/upload/uploadPhoto, this may result in stalled requests. The front end includes an input that ca ...

In the world of React Redux, there is a peculiar issue where the "return" statement fails to function within a particular Redux Action function, specifically

Attempting to make updates to a customer's name using React-Redux can be a bit tricky. Below is the component code: import React, { useEffect, useState } from "react"; import { Link, Navigate, useParams } from 'react-router-dom'; i ...

Creating a <Box /> component in MaterialUI with styled components is a great way to customize the design and layout of your

@material-ui/styles offers a different way to customize default styles: import React from 'react'; import Box from '@material-ui/core/Box'; import { styled } from '@material-ui/core/styles'; const StyledBox = styled(Box)({ ...

Fill in the text boxes using an AJAX request

I am currently working on an MVC project that involves filling out forms with user information. Each recorded entry is given a unique Id that is associated with all the details submitted in the form. My next task is to create a page for editing these form ...

The ExpressJS middleware is executing twice

I'm experiencing an issue with the following code snippet. When I include the middleware logger() as the first argument to app.use(), it is called twice. However, when I place it as the second argument, it doesn't get executed at all. Can anyone ...

JQuery triggers form submission after multiple clicks - Validation needed

I'm having trouble understanding why the validation is not working on the first click but works later on. I've added the validate plugin to my JS file so that the form is validated after being clicked. The validator is set when the document is ...

Retrieve information from the third section by utilizing ajax

My current setup involves: Having a form in form.php for inserting data, Displaying data in table format with pagination on display.php, and Using validation.js for validating form data along with the following function: $('#pagiCount a'). ...

Changing the size of text using radio buttons in JQuery MobileIs there a way to modify

I am currently working on adjusting the text size for both header and paragraph information in a listview. Below is the JQuery code that I have implemented: $('#rc1').prop('checked', 'true', function(){ $(".feedContainer ...

Retrieving fresh data from Redis within the client application

Currently, I am utilizing PHP in conjunction with PHPRedis to establish a connection with Redis. The connection is working smoothly. $redis = new Redis(); $redis->connect('localhost', 6379); $total = $redis->get('total'); Assum ...

What is the best way to retrieve a state variable within the getServerSideProps() function in NextJS?

Introduction Greetings everyone, I am a newcomer to NextJS. Currently, I am in the process of developing a weather application that utilizes external APIs. My main task involves fetching data from an API and displaying it on the frontend. Desired Function ...

Angular - service workers leading to unsuccessful uploads

When uploading files using Uppy (XHRUpload) in my Angular 6 app, the process is smooth on localhost with the service worker disabled. However, enabling the service worker results in successful uploads only for small files, while larger files fail to upload ...

Having trouble retrieving the value from the input field with Angular.js

I am having trouble retrieving the value from an input field using Angular.js. Below is the code explanation. Here is my controller code: $scope.shipping=0; $scope.addProductInfoData=function(billdata){ console.log('valid',$scope.shippi ...

Implementing Dynamic Script Injection in Angular Controllers for Enhanced HTML Functionality

I'm a total beginner when it comes to Angular and frontend development, so please bear with me if my question seems basic: In my controller, I have the following code where I am populating the $window.user data that is being used in the script [2] ad ...

Unable to retrieve the value of a key from a node object

I'm baffled by how this is even possible For example, when I execute this code: console.error(order.Items[i]); The output is: { ItemURL: '', IsBundle: false, GiftTaxPrice: '0', GiftPrice: '0', GiftNotes: null ...

Running NodeJS scripts with ElectronJS is not possible

Goal I'm facing a challenge with executing my separate scripts located in the project/api folder. Let's take test.js as an example, where I am exporting it using module.exports. When I run my electron window and create a JavaScript file with a f ...

Implement pre-save middleware in Mongoose to perform lowercase validation on a document's

In order to have a user object maintain case sensitivity for display purposes, while being lowercased for uniqueness purposes, I initially considered adding a usernameDisplay property to the schema with a pre-save hook: var userSchema = new Schema({ u ...