Cannot close vaadin application and close browser pop-up window together

A parent application opens a pop up ( to my URL which is a vaadin Application. At the completion of my application, I’d like to close the browser pop up and the vaadin application.
I use the close() method of com.vaadin.Application class to close the vaadin application.
And I tried to use main.executeJavaScript() to close the pop up. main is vaadin main Window of my Application.
I tried both window.close() (the parent and my URL are same domain), and calling a javascript function in parent page.
However, I found that close Application and executeJavaScript don’t work together.
If I call close() Application first, vaadin will shutdown properly, but the javascript (e.g. window.close) will not run so my pop up is not closed.
If I run javascript first, the pop up will close, but vaadin will not shutdown properly. The result of not shutdown properly is that next run of my application will get a blank window.
Any advice on how to solve this problem? Is there another way to shutdown vaadin application but still run javascript in the parent page?
Thanks much for help.

I think you should definitely close the popup first as it is a subpart of the app and then call close on the application. So when you do the JS first and then Application.close(), what actually happens in the main browser and what do you expect. Does it do a redirect somewhere and it is just the next session that fails? Goes the initial close wrong?

Maybe a delay before the close might help, maybe a more explicit action on what should happen on close could be specified. I guess you have an older version of Vaadin if you have the Application class?

Yes, I am still using vaadin 6 unfortunately (6.8.9). It’s not up to me to upgrade the vaadin library.
In case I close pop up first, the code is:
where _main is vaadin main Window and _app is vaadin Applicaton.
When this is run, pop up is closed. But, if I try to run my application again, the pop up is opened and is blank instead of having my panel in it. It feels like that vaadin remembers my application’s state which is closed so it won’t start fresh.
If I don’t have the executeJavaScript line and only have _app.close(), I can run my application repeatedly without problem except that the pop up needs to be closed manually using the browser X button.

Solution: implement a none vaadin servlet that will run window.close(). Then, use setLogoutURL() to redirect the application to this servlet when it is closed.