Global Window Function Not Defined - UXP Browser Limitations

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 library to handle gluing Rust, WebAssembly, and JavaScript together.

When using this DOM example from the web-sys library to manipulate the elements in the UXP browser, I get a nasty Window is not defined error.

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 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?



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?

1 Like

Ahh no luck.

Looks like there could be a workaround 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!

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

Yep, still getting the Window is not defined error when creating the alias. :thinking:

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.

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.