WebWorkers compatibility

The window object doesn't exists in webworkers, self must be used instead.