@@ -26,22 +26,28 @@ var endsWith = function (str, suffix) {
26
26
return str . indexOf ( suffix , str . length - suffix . length ) !== - 1 ;
27
27
} ;
28
28
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 .
30
30
// 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 ) {
34
48
return false ;
35
49
}
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 ;
45
51
} ;
46
52
47
53
var CURRENT_VERSION = '1.2.0' ;
@@ -228,7 +234,7 @@ function doNotTrack () {
228
234
229
235
function isTelemetryDisabled ( ) {
230
236
// 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 ) ;
232
238
}
233
239
234
240
} ) ( window ) ;
0 commit comments