Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to use web_sys::window() fails in webworker #655

Closed
wellcaffeinated opened this issue May 23, 2019 · 1 comment
Closed

Attempting to use web_sys::window() fails in webworker #655

wellcaffeinated opened this issue May 23, 2019 · 1 comment

Comments

@wellcaffeinated
Copy link

🐛 Bug description

Loading a wasm-pack module that tries to use web_sys::window() in a webworker fails because "Window" is not defined (capitalized).

This is due to this line of code in the built module .js file:

// ...
export function __widl_instanceof_Window(idx) { return getObject(idx) instanceof Window ? 1 : 0; }
// ...

I tried changing this line to be something (naive):

export function __widl_instanceof_Window(idx) { var Win = 'Window' in self ? Window : DedicatedWorkerGlobalScope; return getObject(idx) instanceof Win ? 1 : 0; }

And this works.

Recommend you find a different way to check for instance of Window that doesn't rely on the Window class being in the global scope.

🤔 Expected Behavior

Should load correctly.

👟 Steps to reproduce

  1. Create a simple rust module that tries to use web_sys::window()
  2. build it for webpack
  3. Load it in a webworker with worker-loader (i'm using workerize-loader... and waiting on a fix Fix for #67 developit/workerize-loader#68)

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: 0.8.1
rustc version: 1.34.1 (fc50f328b 2019-04-24)

@wellcaffeinated
Copy link
Author

ah jeeze sorry. Wrong repo.
Already reported here:
rustwasm/wasm-bindgen#1046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant