This function can be used as both a setter (if `enabled` is provided) or a getter (if it isn't).  If enabled isn't passed as an argument, it will be undefined, so we return a boolean indicating whether we've enabled the warning.

The getter is basically only used in tests to encapsulate the tests from directly checking `window.onbeforeunload`.