# Global Window Function Not Defined - UXP Browser Limitations

**URL:** <https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509>\
**Category:** UXP Developer Tool\
**Created:** [August 16, 2021, 11:14pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509 "2021-08-16T23:14:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake-pauls](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jake-pauls/32/1488_2.png) [@jake-pauls](https://forums.creativeclouddeveloper.com/u/jake-pauls)\
**Post date:** [August 16, 2021, 11:14pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/1 "2021-08-16T23:14:58Z")

</div>

Been wrestling with UXP a bit for this one but I thought I’d see if anyone in the community had any ideas. I’ve been working on a sample that leverages the [wasm-bindgen](https://rustwasm.github.io/docs/wasm-bindgen/) library to handle gluing Rust, WebAssembly, and JavaScript together.

When using this DOM example from the [web-sys](https://rustwasm.github.io/docs/wasm-bindgen/examples/dom.html) library to manipulate the elements in the UXP browser, I get a nasty `Window is not defined` error.

 ![windowbug](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/0/03d561a3ede1e0316f0b80fdee89eb042a76af89.png)

As per the screenshot, this works perfectly in a traditional web browser. Based on some of the other obstacles I’ve had in making this sample work, I’m assuming this is part of the modern browser limitations of UXP.

I tried using [node-window-polyfill](https://www.npmjs.com/package/node-window-polyfill) to inject the Window global to no avail. Does anyone have any other ideas or insights to get this going? Or should I take note of this as a current limitation?

Thanks!

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [August 17, 2021, 3:37pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/2 "2021-08-17T15:37:27Z")

</div>

Hmm.

It looks like it’s expecting `window` to be of type `Window` – in UXP, `window` is aliased to `global` (more like Node).

I wonder if just setting `Window = window` or `Window = window. __proto__ ` before invoking the web assembly portion would get it to behave?

---

<div class="post-metadata">

**Author:** ![jake-pauls](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jake-pauls/32/1488_2.png) [@jake-pauls](https://forums.creativeclouddeveloper.com/u/jake-pauls)\
**Post date:** [August 17, 2021, 11:41pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/3 "2021-08-17T23:41:10Z")

</div>

Ahh no luck.

Looks like there could be a [workaround](https://github.com/rustwasm/wasm-bindgen/issues/896) although it’s on the actual API implementation I believe (not to mention outdated). These solutions didn’t quite yield the result I wanted either.

However, thanks @kerrishotts, I’ll keep digging!

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [August 18, 2021, 7:16pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/4 "2021-08-18T19:16:12Z")

</div>

When aliasing `Window`, was the error the same, or was it able to get a little further?

---

<div class="post-metadata">

**Author:** ![jake-pauls](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jake-pauls/32/1488_2.png) [@jake-pauls](https://forums.creativeclouddeveloper.com/u/jake-pauls)\
**Post date:** [August 18, 2021, 9:55pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/5 "2021-08-18T21:55:34Z")

</div>

Yep, still getting the `Window is not defined` error when creating the alias. 🤔

I’m wondering if it has something to do with `wasm-bindgen` searching specifically for an `instanceof Window`. In this case, I’m not sure if the `Window` constructor is anywhere in UXP’s `window` global, which would lead to these exceptions.

I’ve developed the sample to behave around this issue for now. However, DOM manipulation using the `web-sys` library won’t be possible until a way is found to work around this.

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [August 19, 2021, 2:22pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/6 "2021-08-19T14:22:23Z")

</div>

Another thought to try – add a `<script>` tag in your HTML file _above_ `index.js`, that does the alias. Sometimes I’ve had success w/ that when trying to convince something like redux devtools to to work.

---

<div class="post-metadata">

**Author:** ![cameronmcefee](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/cameronmcefee/32/2173_2.png) [@cameronmcefee](https://forums.creativeclouddeveloper.com/u/cameronmcefee)\
**Post date:** [May 19, 2022, 11:49pm UTC](https://forums.creativeclouddeveloper.com/t/global-window-function-not-defined-uxp-browser-limitations/3509/7 "2022-05-19T23:49:49Z")

</div>

Adding my own experience and to summarize the thread since I just came across this myself — The solution is like @kerrishotts suggested, to place it in a `<script>` tag before your index.js.

```auto
<script>
  // In my case, Recoil is evaluating `window instanceof Window`
  // so you need to assign it to the constructor, not the window 
  // object itself.
  Window = window.constructor
</script>

```
