Re: Value returned by navigator.doNotTrack

It seems wrong to be conditioning an if statement on a ternary value
anyway.  If you want to make that fail, then maybe you should make it
a string.  You could use the values used informally in the draft spec,
"OPT-IN", "OPT-OUT", and "NO-EXPRESSED-PREFERENCE" [1].  Maybe via an
enum.

if (navigator.doNotTrack == DNT.optIn) { /* track */ }
else if (navigator.doNotTrack == DNT.optOut) { /* don't track */ }
else if (navigator.doNotTrack == DNT.noExpressedPreference) { /*
probably track anyway */ }
else { /* there is no else */ }

--Richard

[1] <http://tools.ietf.org/html/draft-mayer-do-not-track-00#section-6.1>



On Wed, Dec 21, 2011 at 3:47 PM, Justin Lebar <jlebar@mozilla.com> wrote:
> On Wed, Dec 21, 2011 at 3:28 PM, Richard Barnes
> <richard.barnes@gmail.com> wrote:
>> How about just using NaN?  That would be consistent with just calling
>> parseInt() on the content of the header ("0", "1", or "").
>
> If we made navigator.doNotTrack a number (0, 1, NaN), then
>
>  if (navigator.doNotTrack)
>
> would work correctly.  But then the negation,
>
>  if (!navigator.doNotTrack)
>
> is not right.  :)
>
>> On Wed, Dec 21, 2011 at 2:00 PM, Justin Lebar <jlebar@mozilla.com> wrote:
>>> In Firefox, we implemented navigator.doNotTrack to return either
>>>
>>>  "unspecified", if the user has not opted in to DNT, or
>>>  "yes", if the user has opted in to DNT.
>>>
>>> The proposed DNT spec has us return "1" if the user has opted in to
>>> DNT and doesn't seem to specify what we should return otherwise.
>>>
>>> I propose the spec be modified to explicitly state what UAs should
>>> return if the user has not opted in to DNT, and to use unspecified/yes
>>> instead of ??/1.
>>>
>>> DNT is a tri-state, not a boolean.  The DNT http header may be 1, 0,
>>> or not present.  0 indicates that the user has explicitly opted in to
>>> tracking.  Although Firefox doesn't support this option at the moment,
>>> we'd like to spec DNT in such a way as to allow users to explicitly
>>> opt in to tracking.  We propose that navigator.doNotTrack == "no"
>>> correspond to DNT: 0.
>>>
>>> It's confusing that navigator.doNotTrack's value doesn't correspond to
>>> the value of the HTTP header, but we did this because we wanted to
>>> protect against buggy JS which assumes navigator.doNotTrack is a
>>> boolean.  If we were to use navigator.doNotTrack == '' for users who
>>> have neither oped in nor out of DNT, then sites could do |if
>>> (navigator.doNotTrack) { // don't track me }|.  This would make it
>>> difficult for us to introduce navigator.doNotTrack = "no" in the
>>> future, because "no" resolves to the boolean |true|.
>>>
>>> I've filed a webkit bug on this issue [1].
>>>
>>> [1] https://bugs.webkit.org/show_bug.cgi?id=75008
>>>

Received on Wednesday, 21 December 2011 20:57:48 UTC