Replace window.onmessage with window.addEventListener