Skip to content

Commit e62ab22

Browse files
update window.browser spec per #532 (#546)
* update window.browser spec per #532 Co-authored-by: Rob Wu <[email protected]>
1 parent 0bcc7db commit e62ab22

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

specification/window.browser.bs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,40 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
5252
it MUST be used only for WebExtension related functionality.
5353
</section>
5454

55+
<section>
56+
For backwards compatibility with older versions of WebExtensions that used
57+
<code>chrome</code> as a global identifier for WebExtension related methods,
58+
a UA MAY define a global <code>chrome</code> object that includes all
59+
properties of {{browser}}.
60+
{{browser}} and <code>chrome</code> MAY be direct aliases of each other.
61+
When {{browser}} and <code>chrome</code> are distinct objects, each initial
62+
property of {{browser}} SHOULD be defined on the <code>chrome</code> object,
63+
and each property descriptor on the <code>chrome</code> object SHOULD return
64+
the same value as the corresponding property on the {{browser}} object.
65+
66+
<div class="example" id="example-1">
67+
Here's an example of the expected alias behavior
68+
<pre><code class="lang-js">
69+
// When `chrome` and `browser` are not direct aliases,
70+
// modifying one top level values will not change the other:
71+
72+
globalThis.browser.FAKE = true
73+
console.log(globalThis.chrome.FAKE);
74+
// ^ undefined when chrome and browser are not direct aliases.
75+
// ^ may be true if browser === chrome.
76+
77+
// Individual properties are aliased, so updating a known property
78+
// directly changes the matching property on the other
79+
globalThis.browser.runtime.FAKE = 123
80+
81+
console.log(globalThis.chrome.runtime.FAKE);
82+
// 123
83+
</code></pre>
84+
85+
</div>
86+
87+
88+
</section>
5589

5690
<pre class="idl">
5791
partial interface Window {

0 commit comments

Comments
 (0)