-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(do-not-track): window object can be undefined #479
- Loading branch information
Showing
2 changed files
with
49 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
// Read the Mozilla Do Not Track Field Guide | ||
// (https://developer.mozilla.org/en-US/docs/Web/Security/Do_not_track_field_guide), | ||
// for information on how to use the donottrack | ||
// gathering data of actions of an user as long as it is not associated to the | ||
// gathering data of actions of a user as long as it is not associated to the | ||
// identity of that user, doNotTrack is not enabled here. | ||
|
||
import {hasNavigator} from './detector'; | ||
import {hasNavigator, hasWindow} from './detector'; | ||
|
||
const doNotTrackValues = ['1', 1, 'yes', true]; | ||
|
||
export function doNotTrack(): boolean { | ||
return ( | ||
hasNavigator() && | ||
[ | ||
(<any>navigator).globalPrivacyControl, | ||
(<any>navigator).doNotTrack, | ||
(<any>navigator).msDoNotTrack, | ||
(<any>window).doNotTrack, | ||
].some((value) => doNotTrackValues.indexOf(value) !== -1) | ||
); | ||
const checks: any[] = []; | ||
if (hasWindow()) { | ||
checks.push((<any>window).doNotTrack); | ||
} | ||
if (hasNavigator()) { | ||
checks.push((<any>navigator).doNotTrack, (<any>navigator).msDoNotTrack, (<any>navigator).globalPrivacyControl); | ||
} | ||
return checks.some((value) => doNotTrackValues.indexOf(value) !== -1); | ||
} | ||
|
||
export default doNotTrack; |