debug icon indicating copy to clipboard operation
debug copied to clipboard

Web Worker compatibility

Open Joris-van-der-Wel opened this issue 9 years ago • 9 comments

Over at jsdom, our web worker test fail if we update our dependencies. Here is the error that I got:

ReferenceError: window is not defined at https://github.com/visionmedia/debug/blob/17d0e0bb49b46f53bd97aa6d7b56bf9990a8cb62/browser.js#L13

This line is missing a typeof window !== 'undefined' check. This check is present in other locations in this file, so this issue looks like a small oversight.

After #378 is resolved, you might be interested in https://www.npmjs.com/package/karma-mocha-webworker @yamikuronue

Joris-van-der-Wel avatar Dec 18 '16 23:12 Joris-van-der-Wel

This broke with 1c625d4, which landed in yesterday's version 2.4.5 release.

KlausTrainer avatar Dec 19 '16 10:12 KlausTrainer

Crap! Yup, this is totally on me. Will submit an update shortly

thebigredgeek avatar Dec 20 '16 00:12 thebigredgeek

@thebigredgeek I find you have a commit six hours ago, do you fix it?

if (typeof window !== 'undefined') {
  exports.storage = 'undefined' != typeof window.chrome
               && 'undefined' != typeof window.chrome.storage
                  ? window.chrome.storage.local
                  : localstorage();
} 
else {
  exports.storage = localstorage();
}

lirongfei123 avatar Dec 21 '16 02:12 lirongfei123

This should be fixed for 2.5.x Can you confirm?

thebigredgeek avatar Dec 21 '16 05:12 thebigredgeek

Also @Joris-van-der-Wel we'd love to integrate that into our workflow. I tried earlier but I kept getting missing framework errors :(

thebigredgeek avatar Dec 21 '16 05:12 thebigredgeek

Also @Joris-van-der-Wel we'd love to integrate that into our workflow. I tried earlier but I kept getting missing framework errors :(

Odd, it is working properly for the jsdom repo. This is our configuration file for jsdom: karma-webworker.conf.js, however it is a bit extra complicated because it has to deal with browserify. Here is a travis build that uses it.

You can find more example configurations in the test directory of karma-mocha-webworker

Joris-van-der-Wel avatar Dec 22 '16 18:12 Joris-van-der-Wel

This should be fixed for 2.5.x Can you confirm?

Almost ;), the issue still occurs on line 185:

/** Attach to Window*/
if (window) {
  window.debug = exports;
}

This line should be if (typeof window !== 'undefined') {

Alternatively, you could replace all instances of window with self. This works within a worker, but also outside of a worker.


I noticed that a lot of other modules pin debug to specific versions instead of using a version range, I end up with 13 different copies of debug in jsdom. Luckily the only one that ends up in my browserify bundle is pinned at ^2.0.0.

Joris-van-der-Wel avatar Dec 23 '16 11:12 Joris-van-der-Wel

@thebigredgeek any traction on this? We're almost there. Need to close issue on jsdom and currently blocked. /cc @Joris-van-der-Wel

snuggs avatar Dec 25 '16 03:12 snuggs

On it right now. Merry Christmas everyone!

thebigredgeek avatar Dec 26 '16 02:12 thebigredgeek