How to execute current window's js function from menu?

So, this is my first time using electron to build a app from html & js. Now here’s my problem my app starts with a page say index.html , from there I can go to a new page say new.html . This new.html loads a js file which has a custom undo function that can be used on the page. Now I want to execute that undo function from the app menu. I can add the menu for usual cases and everything in new.html page works without any problem. But I don’t know how to link that particular function to the menu item. I tried checking the webcontents but couldn’t figure out what to do. Can anyone please help me with this?