Can you close the PWA programmatically?

Hello,
can you close the Vaadin PWA programmatically? I already tried

UI.getCurrent().getPage().executeJS("close()");

and

UI.getCurrent().close();

but this didn’t work.
Best Regards
Mats

UI.getCurrent().getPage().executeJS("window.close();");

It should work when you are in Production mode.

Syam Pillai:

UI.getCurrent().getPage().executeJS("window.close();");

It should work when you are in Production mode.

How to toggle Production Mode when running using the IntelliJ Run Configuration (Application.java)?

See [Preparing your application for Production]
(https://vaadin.com/docs/flow/production/tutorial-production-mode-basic.html) in the Vaadin Docs

Syam Pillai:

UI.getCurrent().getPage().executeJS("window.close();");

It should work when you are in Production mode.

No, that didn’t work. I let the program print something out when the command ran…
the windows wasn’t closed like this. I saw the output “Vaadin is running in production mode.”.

Maybe I should provide pieces of my version information?

  • Vaadin 14.3.0
  • Spring Boot 2.2.0-RELEASE
  • openJDK (Coretto) 11

Matsi Katzi:

Syam Pillai:

UI.getCurrent().getPage().executeJS("window.close();");

It should work when you are in Production mode.

No, that didn’t work. I let the program print something out when the command ran…
the windows wasn’t closed like this. I saw the output “Vaadin is running in production mode.”.

Maybe I should provide pieces of my version information?

  • Vaadin 14.3.0
  • Spring Boot 2.2.0-RELEASE
  • openJDK (Coretto) 11

I am using 16.0.1. It doesn’t close the window when used inside the browser. However, if I install it as a PWA app on the desktop or mobile, then it closes the app properly.

Syam Pillai:

I am using 16.0.1. It doesn’t close the window when used inside the browser. However, if I install it as a PWA app on the desktop or mobile, then it closes the app properly.

I haven’t tried it in PWA before, tried it now and it still isn’t working. I wrote the function in the UI.onAttach Method:

@Override
    protected void onAttach(AttachEvent attachEvent) {
        final UI ui = attachEvent.getUI();
        CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS).execute(() -> {
            ui.access(() -> ui.getPage().executeJs("window.close();"));
        });
    }

By specification, only windows that are opened via scripts can be closed via w.close() call.
In my application, I have a “logout” button that cleans up certain things and executes the JS “window.close();”. It works when the application is installed as a PWA app.

Syam Pillai:
By specification, only windows that are opened via scripts can be closed via w.close() call.
In my application, I have a “logout” button that cleans up certain things and executes the JS “window.close();”. It works when the application is installed as a PWA app.

I have an logout button too, it redirects to the Spring Security Address which logouts. Then Spring Security accesses my View with that function