I have one main parent app with a home button which navigates the user to the main parent app landing page using document.location. My parent app renders a lot of vanilla javascript applications on run time using tiles. Each tile within my parent app represents the child vanilla js app which doesn't share its context with the parent app. Now within the child app user can initiate or execute a function which can take around a few seconds to a minute (don't ask why please). Within that time, the user can click the parent home button. Now my main question is how do I make sure that I complete my child's function execution (which is a promise) before the parent completes navigation or even initiates the navigation. Is there any workaround to this problem? I wish I could change this design but it is a legacy application with not much room for innovation.
One solution I can think of:-
When parent app starts navigation, during that event execution add script tag to the parent. In that script tag then I can run my custom code.