title: Why is referencing `window.location` considered a bad practice?
body: <p>While building a shared library for internal use, which will be used by several teams for Angular applications. These applications will only run in the browser. I've used the code below to construct a <code>returnUrl</code> - to which a user returns after logging in with an external identity provider like Keycloak.</p>
  <pre class="lang-js prettyprint-override"><code>private _iframeRedirectUri = `${window.location.origin} ... the rest of the url`;
  </code></pre>
  <p>In the PR I made, a co-worker made comments regarding <code>window.location.origin</code>. He stated that referencing the native web apis is considered a bad practice and I should use a library like <code>ng-web-apis</code> (<a href="https://github.com/ng-web-apis/" rel="nofollow noreferrer">https://github.com/ng-web-apis/</a>) and getting the <code>location.origin</code> like this:</p>
  <pre class="lang-js prettyprint-override"><code>private _iframeRedirectUri = `${this.location.origin} ... the rest of the url`;
  
  constructor(@Inject(LOCATION) readonly location: Location) {}
  
  </code></pre>
  <p>When looking at the source code of ng-web-apis, the <code>LOCATION</code> token looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>export const LOCATION = new InjectionToken&lt;Location&gt;(
      'An abstraction over window.location object',
      {
          factory: () =&gt; inject(WINDOW).location,
      },
  );
  
  // And window:
  
  export const WINDOW = new InjectionToken&lt;Window&gt;(
      'An abstraction over global window object',
      {
          factory: () =&gt; {
              const {defaultView} = inject(DOCUMENT);
  
              if (!defaultView) {
                  throw new Error('Window is not available');
              }
  
              return defaultView;
          },
      },
  );
  </code></pre>
  <p>What's the point in this abstraction when these application will never run in a backend and <em>always</em> in the browser? Discussing this with my co-worker results in &quot;it's just evil&quot; and &quot;never reference stuff like window or document&quot;, so that's not helping me <em>why</em>. Can anyone help me understand this issue?</p>