This is a proposal for new Event indicating changes to the navigator.doNotTrack
property.
The lifetime of client script will be at least as long a web page exists within a user agent, and much longer if it is associated with a shared web or service worker.
Whenever the script tiggers an HTTP request for a resource on the document origin, such as by the execution of an XmlHttpRequest
API call or the creation of an Image
object,
the value of the DNT request header included will be determined by the user agent, "taking into account the user's general preference (if any) and any user-granted exceptions applicable to that origin server". This DNT header value is available to the script via the navigator.doNotTrack
property.
Client script is always event based, either triggered when a browsing context is loaded, a DOM element is clicked, a timer duration has elapsed, or for many other reasons. Some may be caused by actions in other execution contexts within the user agent. Without an event indicating a change in the calculated value of the DNT header the script must be triggered by other events, e.g. a timing event. This can result is an arbitary delay being introduced into the script execution, and processing inefficiency.
This proposal is for an event indicating a change in the DNT header, as a result of:
storeSiteSpecificTrackingException
in the same or a parent browsing context.
storeWebWideTrackingException
.
removeSiteSpecificTrackingException
in the same or a parent browsing context.
removeWebWideTrackingException
.
maxAge
or expires
duration elapses.
In addition the existance of a DNT change event provides an execution context in which the value of navigator.doNotTrack
can be guarenteed,
allowing client script (i.e. a "polyfill" library) to emulate the functionality of the User Granted Exception
mechanism when it is not nataively supported in the user agent.
doNotTrack
event
The doNotTrack
event is fired on a Document
's
Window
object when the DNT header field to be sent in requests to the document origin is changed. It will be triggered whenever the value of navigator.doNotTrack
is changed, for any reason, whether this is the result of Exception API calls in the current or other browsing contexts, or the result of revocation by the user or automatically after an associated duration expires.
A doNotTrack
event will always be fired at least once, and as soon as possible after a browsing context has been loaded.
When a user agent is to send a doNotTrack change notification for a Document
, the
user agent must queue a task to fire a trusted event with the name doNotTrack
, which
does not bubble and is not cancelable, and which uses the DNTEvent
interface, at
the Document
object's Window
object.
The task source for these tasks is the Tracking Protection task source.
DoNotTrackChangeEvent
interface[Constructor(DOMString type, optional DoNotTrackChangeInit eventInitDict)] interface DoNotTrackChangeEvent : Event { readonly attribute DOMString? doNotTrack; }; dictionary DNTEventInit : EventInit { DOMString? doNotTrack; };
The doNotTrack
attribute must return the value it
was initialized to. When the object is created, this attribute must be initialized to null. It
represents the same string value that would be sent in a DNT-field-value
(section 5.2 DNT Header Field for HTTP Requests) to a
target that is the document-origin of the window
, in the browser context of the current top-level origin. It will always be identical
to the value returned from reading navigator.doNotTrack
within the Event callback function.