Don't repeat yourself and fix logging to stderr
This MR refactors some code that was duplicated for all service workers and/or client scripts.
Additionally, it fixes logging to stderr instead of a file.
This MR refactors some code that was duplicated for all service workers and/or client scripts.
Additionally, it fixes logging to stderr instead of a file.