blob: 2046870754068e1a20d55bc32b6f517b2b5e394e [file] [log] [blame] [view]
Domenic Denicolacae2b5a2022-02-07 16:49:491# `document.domain` Setting is Deprecated
Daniel Vogelheim2c609dc2022-02-04 18:14:252
Domenic Denicolacae2b5a2022-02-07 16:49:493Setting [`document.domain`](https://developer.mozilla.org/en-US/docs/Web/API/Document/domain)
Daniel Vogelheim2c609dc2022-02-04 18:14:254is [deprecated](https://html.spec.whatwg.org/multipage/origin.html#relaxing-the-same-origin-restriction).
Domenic Denicolacae2b5a2022-02-07 16:49:495`document.domain` setting can be used to relax the same-origin restrictions
Daniel Vogelheim2c609dc2022-02-04 18:14:256between different frames, hosted within the same site but on different origins.
7Doing so make themselves effectively same-origin for the purpose of
8synchronous access.
9
10For example, `https.//www.example.test/` might host a media player on
11`media.example.org`. If both the main page and the frame execute
12`document.domain = "example.org";` they may then access each others' DOM
13tree, which they normally couldn't. (A better way would be to cooperate
Domenic Denicolacae2b5a2022-02-07 16:49:4914by `postMessage()`.)
Daniel Vogelheim2c609dc2022-02-04 18:14:2515
16This usage is now being deprecated. (More information can be found
17[here](https://developer.chrome.com/blog/immutable-document-domain/) and
18[there](https://github.com/mikewest/deprecating-document-domain)).
19
20## What is happening, and when?
21
22* M100: Chrome will show deprecation warnings when document.domain is set.
23* M106: Chrome will disable document.domain by default.
24
25Note that the second milestone is tentative: When the time comes, we will
26examine how many pages will be impacted by this change, and will start a
27separate discussion (intent to remove) on the
28[blink-dev mailing list](https://groups.google.com/a/chromium.org/g/blink-dev).
29
Domenic Denicolacae2b5a2022-02-07 16:49:4930## `document.domain` and Origin-keyed Agent Clusters
Daniel Vogelheim2c609dc2022-02-04 18:14:2531
Domenic Denicolacae2b5a2022-02-07 16:49:4932Most documentation on this change is phrased in terms of origin-keyed
33agent clusters. This is [a concept in the HTML
Daniel Vogelheim2c609dc2022-02-04 18:14:2534specification](https://html.spec.whatwg.org/multipage/origin.html#origin-keyed-agent-clusters).
35Here we focus on the behaviour of the `document.domain` setter, which is
36the visible effect.
37
38A web browser can cluster sites (in order to assign them to operating
39system processes) and sites can be clustered by origin, or by site.
40Origin-keyed agent clustering is preferable for security reasons. However
41when sites are clustered by origin, synchronous access to frames outside of
42that origin (but within the same site) is no longer possible. Thus sites in
43origin-keyed agent clusters disable the `document.domain` setter. This is the
44mechanism underlying this change: From M106 on pages will be assigned to
45origin-keyed agent clusters by default and therefore `document.domain`
46will no longer be settable by default, either.
47
48This also gives us an opt-out mechanism for pages who do not wish to follow
49this change: By setting the `Origin-Agent-Cluster: ?0` http header, a site
50can request assignment to a site-keyed agent cluster, and `document.domain`
51will continue to work for them as it currently does. Note that adding this
52header has no other observable effect and thus retains the current
53(pre-M106) behaviour. This makes it an easy and _safe_ way to opt-out.
54
55Setting this header is a no-op in current versions of Chromium since it
56matches the default setting, and will preserve this behaviour in the future.
57It is also a no-op in other browsers, since they either match Chromium's
58current default or have not implemented the `Origin-Agent-Cluster` header at
59all.
60
Daniel Vogelheim97651350d2022-03-18 10:46:1261## Where are the deprecation warnings found?
62
63The deprecation warnings are found in the [issues tab](https://developer.chrome.com/docs/devtools/issues/).
64
65## What does the deprecation warning tell me?
66
67There are two deprecation warnings: One for setting the `document.domain`
68accessors, which modifies the security behaviour. And from M101 on,
69a second warning when a cross-domain access is made that is facilitated by
70the modified `document.domain` property. The first warning tells you where
71the setup happens, and the second one tells you where it is being used (and
72thus likely why this is being done in the first place).
73
Domenic Denicolacae2b5a2022-02-07 16:49:4974## How Can I Test This?
Daniel Vogelheim2c609dc2022-02-04 18:14:2575
76In the DevTools console, for a page `www.example.test`:
77
78```
79document.domain = "example.test";
80document.domain; // "example.test" in a site-keyed agent cluster.
81 // "www.example.test" in an origin-keyed agent cluster.
82```
83
84One can also directly query whether a page is assigned to an origin-keyed
85agent cluster, by querying `window.originAgentCluster`.
86
87```
Domenic Denicolacae2b5a2022-02-07 16:49:4988window.originAgentCluster; // true, if page is assigned to an origin-keyed
Daniel Vogelheim2c609dc2022-02-04 18:14:2589 // agent cluster.
90```
91
92How to enable/disable the deprecation:
93
Daniel Vogelheim97651350d2022-03-18 10:46:1294### Enable the Warning (Before M100)
Daniel Vogelheim2c609dc2022-02-04 18:14:2595
96* Start Chrome with `--enable-features=OriginAgentClusterDefaultWarning`
97
Domenic Denicolacae2b5a2022-02-07 16:49:4998### Enable the Deprecation (Scheduled for M106)
Daniel Vogelheim2c609dc2022-02-04 18:14:2599
100* In [chrome://flags](chrome://flags#origin-agent-cluster-default), go to
101 the "Origin Agent Cluster Default" setting and enable it.
102* Or start Chrome with `--enable-features=OriginAgentClusterDefaultEnable`
103* Or add the `Origin-Agent-Cluster: ?1` header to your pages and frames.
104 (E.g. in a testing instance of your site.)
105
106### Testing at Scale / Reporting API
107
108The deprecation warnings are delivered through the
109[Reporting API](https://web.dev/reporting-api/). They can
110be pragrammatically processed using `ReportingObserver`. For example, the
111first code snippet in
112https://developers.google.com/web/updates/2018/07/reportingobserver
113will report these warnings. The message object delivered by this API is a
Domenic Denicolacae2b5a2022-02-07 16:49:49114[`DeprecationReportBody`](https://developer.mozilla.org/en-US/docs/Web/API/DeprecationReportBody)
Daniel Vogelheim2c609dc2022-02-04 18:14:25115instance which offers information about the source code location that triggered
116the warning.
117
118## What can I do?
119
120If your site does not use `document.domain` setting you don't have to do
121anything. You could explicitly set the `Origin-Agent-Cluster: ?1` header.
122But after M106 this would be the default behaviour anyhow.
123
Domenic Denicolacae2b5a2022-02-07 16:49:49124If your site uses `document.domain` setting to enable cross-origin Javascript
Daniel Vogelheim2c609dc2022-02-04 18:14:25125access, you should refactor the code to instead use
Domenic Denicolacae2b5a2022-02-07 16:49:49126[`window.postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) (or any other mechanism) to cooperate across origins. Or alternatively
127reduce the need for cross-origin cooperation by moving the cooperating pieces
Daniel Vogelheim2c609dc2022-02-04 18:14:25128onto the same origin.
129
130## What if I don't have the time right now, or want to continue setting `document.domain`?
131
Domenic Denicolacae2b5a2022-02-07 16:49:49132You can add the `Origin-Agent-Cluster: ?0` HTTP header to your site. Note that
Daniel Vogelheim2c609dc2022-02-04 18:14:25133the header must be set both for the main page, as well as for the embedded
134frame(s) that wish to use `document.domain` setting.
135
136## Enterprise Users
137
138Users of [Chrome for Enterprise](https://chromeenterprise.google/) can set
139the `OriginAgentClusterDefaultEnabled` policy to `False` to retain the
140current (pre-M106) default for all of their users, until all their internal
141sites and customers have migrated off of `document.domain` usage.
142