check module is defined before adding exports

on chrome extensions, the test typeof exports === "object"  is not enough (it can pass and then reach the module.exports line that throws an exception). so I added the typeof module != "undefined" which solved the problem in the case of my chrome extension.