"not defined" window in web worker. Is this a bug?

I am running into an issue trying to load a model into a web-worker via the indexedDB.

Specifically, I am getting a ReferenceError: window is not defined when trying to use: tf.loadLayersModel(“indexeddb://model_name”)

I found in the indexed_db.js file line 51
const theWindow = window || self;

however, it appears that window in a webworker is “not defined” rather than “undefined” which throws an error rather than being coerced into falsy

Just wondering if this is indeed unintended behavior

It sounds like this might be the same issue described here on GitHub. Can you share what version of TensorFlow.js you’re using? If it is up to date, I’ll re-open the issue and reference your post.

In the issue, one dev suggests:

As a temporary solution, I added window = globalThis; in my worker.js file and it works.

Let me know if that workaround helps in the meantime, and then I’ll open the issue if need be.

Yes, that is pretty much how I worked around the issue too.

As I was writing my response I figured out I was not running the latest version of TF. It appears in 3.20.0 the issue has already been resolved.

Thanks for the response.

Glad to hear it! I can’t wait to see what you build :slight_smile: