Skip to content

webchannel-wrapper build process not compatible with web worker #285

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

Closed
PCreations opened this issue Nov 1, 2017 · 4 comments
Closed

webchannel-wrapper build process not compatible with web worker #285

PCreations opened this issue Nov 1, 2017 · 4 comments

Comments

@PCreations
Copy link

PCreations commented Nov 1, 2017

Describe your environment

  • Operating System version: OSX 10.12.1
  • Firebase SDK version: 4.6.0
  • Firebase Product: firestore 4.5.2

Describe the problem

When trying to use firestore inside a webworker, the window object is not set to the self variables, as it is for auth build process for example, thus making firestore to fail as if we were trying to use the browser sdk in a node environnement.

I think the problem lies in the Closure compiler code of the webchannel-wrapper :
webchannel-wrapper/tools/build.js

// actual code
closureBuilder.build({
  name: 'firebase.webchannel.wrapper',
  srcs: glob([resolve(__dirname, '../src/**/*.js')]),
  externs: [resolve(__dirname, '../externs/overrides.js')],
  out: 'dist/index.js',
  options: {
    closure: {
      output_wrapper:
        "(function() {%output%}).call(typeof window !== 'undefined' ? window : this)",
      language_out: 'ECMASCRIPT5',
      compilation_level: 'ADVANCED_OPTIMIZATIONS'
    }
  }
});

// I think this should be done like this :
closureBuilder.build({
  name: 'firebase.webchannel.wrapper',
  srcs: glob([resolve(__dirname, '../src/**/*.js')]),
  externs: [resolve(__dirname, '../externs/overrides.js')],
  out: 'dist/index.js',
  options: {
    closure: {
      output_wrapper:
        "(function() {%output%}).call(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {})",
      language_out: 'ECMASCRIPT5',
      compilation_level: 'ADVANCED_OPTIMIZATIONS'
    }
  }
});

When modifying this file, and yarn linking the package manually, I get rid of the "nodejs" like error (k.setTimeout is not defined, etc.) but some others pop out from browser.window dependent method like Image that are not defined in a webworker environnement (this error commes from the goog.net.WebChannel package).
Any chance to add support for using firestore in webworker ?

@mikelehen
Copy link
Contributor

mikelehen commented Nov 28, 2017

We resolved the webchannel / Image issue separately. Can you try your workaround again and see if the webworker issue is resolved? If so, we can likely get your change implemented (if you're willing, a PR would be most appreciated :-))

@r0bn
Copy link
Contributor

r0bn commented Dec 1, 2017

i had the same error message with web workers, i tested the proposed change from @PCreations and it seems to work in web workers.

@PCreations
Copy link
Author

Seems good now ! Maybe we can close this issue when the master branch is released :)

@mikelehen
Copy link
Contributor

Holler if anybody is still seeing issues!

@firebase firebase locked and limited conversation to collaborators Oct 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants