Sentry-javascript: NPM package doesn't work for web workers

Created on 29 Nov 2016  路  6Comments  路  Source: getsentry/sentry-javascript

Current behaviour

When trying to use "raven-js" as npm package from inside web worker (using https://github.com/webpack/worker-loader) it fails with "Uncaught ReferenceError: window is not defined". That's because "singleton.js" exported as "main" attempts to "cache" Raven instance using "window" object which doesn't exist within webworker execution.

Expected behaviour

It is possible to use "raven-js" from web worker using "npm" package.

Most helpful comment

Works beautifully, thank you!

All 6 comments

Thanks for reporting - apparently this is our previously-unfound motivating example for #747. We can add some defensiveness to not blow up when window doesn't exist.

@pbadenski this should be fixed in v3.9.0 now - give it a try and let me know if you run into trouble.

Unfortunately doesn't yet. Now fails at uuid generation:

var crypto = window.crypto || window.msCrypto;

Exception below:

ReferenceError: window is not defined
    at uuid4 (http://localhost:8080/c212583dd96f840b5048.worker.js:2279:19)
    at Raven._getUuid (http://localhost:8080/c212583dd96f840b5048.worker.js:2022:15)
    at Raven._sendProcessedPayload (http://localhost:8080/c212583dd96f840b5048.worker.js:2032:69)
    at Raven._send (http://localhost:8080/c212583dd96f840b5048.worker.js:2018:15)
    at Raven.captureMessage (http://localhost:8080/c212583dd96f840b5048.worker.js:1038:15)
    at callback (http://localhost:8080/c212583dd96f840b5048.worker.js:43102:16)
    at Object.console.(anonymous function) [as error] (http://localhost:8080/c212583dd96f840b5048.worker.js:3121:22)
    at http://localhost:8080/c212583dd96f840b5048.worker.js:3218:26
    at Generator.next (<anonymous>)
    at step (http://localhost:8080/c212583dd96f840b5048.worker.js:3151:192)
    at http://localhost:8080/c212583dd96f840b5048.worker.js:3151:362

Ah, damn. I'm not sure how I missed that window reference, but I opened #792 to fix that.

@pbadenski this should actually be fixed in 3.9.1; I've confirmed it myself with a webworker reporting exceptions to sentry.

Works beautifully, thank you!

Was this page helpful?
0 / 5 - 0 ratings