"Synchronous XMLHttpRequest on the main thread is deprecated" using nodejs app.get or http-server
Asked Answered
W

1

3

I am creating a front end in AngularJS for a backend in node.js. I have the option of two simple node.js front end servers to serve the front end web page: one is a simple app.get in express, the other is using the http-server package.

Whichever front end server code I use, I get the following browser console message in Chrome:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.

To make sure that this was not caused by anything Angular (or Bootstrap) I have cut back my webpage to the following:

<!DOCTYPE html>
<html lang="en" >
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>zoneshark</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>

Why am I getting the error message? Does http-server always cause this error? How can I set up a front end server using nodejs so that this error does not occur (just this simple "hello world" page would be a starting point)?

The server code I am using as an alternative to http-server is:

var express = require('express');
var app = express();

app.get('/', function(req,res) {
  res.sendFile('./index.html', {root: __dirname});
});

app.get(/^(.+)$/, function(req, res) {
  res.sendFile('./' + req.params[0], {root: __dirname});
});

app.listen(80);

Another oddity. From the http-server console, it looks like http-server is serving two resources: /index.html as expected, but also /favicon.ico - which is odd as this is not mentioned anywhere.

The final oddity: this only happens from Chrome. From IE there is no issue, and no favicon.ico is called for.

In Chrome, I have cleared all browsing data, except autofill form data, passwords and content licences.

Wellknown answered 15/2, 2015 at 22:6 Comment(2)
That is a client-side error, so there must be more to your example. The errors refers to something attempting to make a synchronous AJAX request, but your example shows no JS at all. It only comes up in Chrome because it is the only browser that has bothers putting a warning in.Define
See async in the MDN docsDefine
W
4

Thanks for the comments. I have tracked down the issue, and it is within Chrome - more particularly extensions.

The issue is with an extension I have: PropertyWizza v2.0. Disabling this extension clears the problem. I will now uninstall it so it doesn't interfere with my development messages.

This was all deduced because I noticed that I had the same problem when accessing any website - including BBC and GitHub for instance - from any computer in my home, as long as I used Chrome.

My advice to anyone starting to debug front-ends for the first time is to check what errors you get on other websites in all your browsers before you begin. This will provide the "control" for your testing.

Wellknown answered 16/2, 2015 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.