Why this java script failing to rerun the script ?

I am rendering three buttons, when user clicking any of the buttons, It will send that buttons text to URL, where I am reading it using st.qeury_param, but it not working as I script has to rerun once java send the buttons text to url,
here is the script

def custom_sidebar_menu(options, icons, menu_title, current_selection):
menu_items = zip(options, icons)
menu_html = f"“”


{menu_title}


“”"
for option, icon in menu_items:
selected = “nav-link-selected” if option == current_selection else “”
menu_html += f"“”

{option}

“”"
menu_html += “”"


function selectMenu(option) {
console.log('Selected menu item: ’ + option);
console.log('Sending postMessage with value: ’ + option);

            // ✅ Update the top-level URL (outside iframe)
            try {
                const parentUrl = new URL(window.parent.location.href);
                parentUrl.searchParams.set('menu', option);
                window.parent.history.pushState({}, '', parentUrl);
                console.log('Parent URL updated with menu=' + option);
                window.postMessage({type: 'streamlit:rerun'}, '*');
            } catch (e) {
                console.warn("Couldn't access parent location (iframe sandbox?): " + e);
            }
        }
    </script>

Here this block “window.postMessage({type: ‘streamlit:rerun’}, ‘*’);” is failing to rerun the streamlit script