Prevent "illegal invocation" error in chrome