loaded as worker detection and support

starting at line 567, detect if running as worker, if so add message listener