I want to open a new browser tab via BrowserWindowOpener. As for this to work I have to .extend() the opener to a component that must be clicable and clicked but my “triggering” element is not a button, I ended using a trick which consists in a hidden Vaddin button that is “clicked” via Javascript when the user interacts with my regular “interactable” Vaadin component. I assign an id to my “fake”, hidden Vaadin button and add the js code to fire a .click() on it after I do the opener.extend(myFakeButton).
The problem is that the 1st time I do the action the method kind of works as expected. It opens a new browser tab with the proper content. But the 2nd time I do the same action, 2 tabs are opened, and 3 the third time, and so on.
The way I use for adding the code that simulates the click is simply via the JavaScript.getCurrent.execute() method:
JavaScript.getCurrent().execute("document.getElementById('myFakebuttonId').click();");
There’s no matter if I put this in the middle of my java code or if I wrap it inside a JavaScript.getCurrent.addFunction(whatever) block. It’s like if the js code was being added everytime again and again everytime I do the action that triggers its execution. Or like if the target element was being added again each time.
I also tried to add my Javascript as a “component” like stated here: https://vaadin.com/docs/-/part/framework/gwt/gwt-javascript.html
But, unfortunately, I came to a dead when I was trying to “inform” my java code that an element was clicked from javascript.