According to standard :
The window attribute should return a Window object of the Window object viewer. The document attribute should return the Window object of the latest Document object.
The Window value is the context in which all your scripts are evaluated. If it was writable, then the above will not be executed, and the implementation will not follow the specification, so it is not writable.
For similar reasons, you can add properties to the Document , but you cannot override it.
You can verify this by looking at the IDL:
[Unforgeable] readonly attribute WindowProxy window; [Unforgeable] readonly attribute Document document;
source share