@@ -26,22 +26,28 @@ var endsWith = function (str, suffix) {
2626 return str . indexOf ( suffix , str . length - suffix . length ) !== - 1 ;
2727} ;
2828
29- // Check if the origin looks like a production, non-development host (i.e., public and served over HTTPS) .
29+ // Check if the origin looks like a non-public development host .
3030// Relevant reading: https://w3c.github.io/webappsec-secure-contexts/#localhost
31- var isInsecureOrigin = function ( win ) {
32- // Allow HTTPS and HTTP.
33- if ( win . isSecureContext === true || win . location . protocol === 'http:' ) {
31+ var isDevOrigin = function ( win ) {
32+ if ( win . location . hostname === 'localhost' ||
33+ endsWith ( win . location . hostname , '.localhost' ) ||
34+ win . location . hostname === '127.0.1' ||
35+ win . location . hostname . indexOf ( '192.168.' ) === 0 ||
36+ win . location . hostname === '0.0.0.0' ||
37+ win . location . host . indexOf ( '::1' ) === 0 ||
38+ endsWith ( win . location . hostname , '.ngrok.io' ) ||
39+ endsWith ( win . location . hostname , '.localtunnel.me' ) ) {
40+ return true ;
41+ }
42+ // A production URL can start with `http://` or `https://` (but not `file:///`).
43+ if ( win . location . protocol === 'http:' ) {
44+ return false ;
45+ }
46+ // Do not allow insecure-context origin (e.g., `file:///` paths).
47+ if ( 'isSecureContext' in win && win . isSecureContext === true ) {
3448 return false ;
3549 }
36- return (
37- win . location . hostname === 'localhost' ||
38- endsWith ( win . location . hostname , '.localhost' ) ||
39- win . location . hostname === '127.0.1' ||
40- win . location . hostname === '0.0.0.0' ||
41- win . location . host . indexOf ( '::1' ) === 0 ||
42- endsWith ( win . location . hostname , '.ngrok.io' ) ||
43- endsWith ( win . location . hostname , '.localtunnel.me' )
44- ) ;
50+ return true ;
4551} ;
4652
4753var CURRENT_VERSION = '1.2.0' ;
@@ -228,7 +234,7 @@ function doNotTrack () {
228234
229235function isTelemetryDisabled ( ) {
230236 // Telemetry is disabled if DNT is enabled or if the origin appears to be for a development environment.
231- return doNotTrack ( ) || isInsecureOrigin ( window ) ;
237+ return doNotTrack ( ) || isDevOrigin ( window ) ;
232238}
233239
234240} ) ( window ) ;
0 commit comments