We have Google Analytics and Azure Application Insights analytics scripts in our HTML, including Google Analytics. They are in <script>
tags in <head>
. They are causing an error when we are watching with Browsersync, particularly with browser-sync-brunch, since we are using brunch as our build system. Upon watching, however, this error is printed to the console twice (interestingly we have two analytics tags):
XMLHttpRequest cannot load http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1494358571902-4&sid=rhGMlOFa_MbRrYbLAAAD. Request header field x-ms-request-id is not allowed by Access-Control-Allow-Headers in preflight response.
and this error set repeatedly every few seconds:
OPTIONS http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1494358572782-5 400 (Bad Request)
OPTIONS http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1494358572782-5 400 (Bad Request)
XMLHttpRequest cannot load http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1494358572782-5. Response for preflight has invalid HTTP status code 400
I'm fairly certain these analytics scripts are causing the problem because blocking them with uBlock Origin makes it work just fine.
I wondered if it had to do with these script tags being before where the Browsersync tag was injected (immediately inside <body>
tag, see documentation). But moving them to the end of the <body>
tag did not fix the issue.
What is causing this and how can it be mitigated?