fix session.close() and encoding issue in postMessage()