How to close AbstractMainWindow

Hi,
For some reason, when user choose “Leave”, I need my webclient to exit(close current browser tab).
I try to invoke close(CLOSE_ACTION_ID, true); in my AbstractMainWindow code, but raise error that :

UnsupportedOperationException: Close operation for TopLevelWindow is unsupported

How to acheive that close current browser tab?

You cannot close the main window using close. Use the following code to close the browser tab:

JavaScript js = Page.getCurrent().getJavaScript();
js.execute("window.close();");

It does not logout user from the application, it only closes the corresponding browser tab.

Thanks for quick reply.
But it does not work, mainwindow still remains.

I add that code in a popup window close listener.

AbstractLookup editor = (AbstractLookup) openWindow("ubs$SelectUserDuty.edit", WindowManager.OpenType.DIALOG);

editor.addCloseListener((String actionId) -> {
    if (actionId == Window.COMMIT_ACTION_ID) {
        // some logic
    } else {
        JavaScript js = Page.getCurrent().getJavaScript();
        js.execute("window.close();");
    }
});