MV window.focus() and window.blur() nerfed for security. I need a modern solution to creating a pop-under. Explanation below.

I'm in a crunch: working on a game-jam project, and something which I once could do, no problem, no longer works.

The project is Desktopia which is a PC idle game that only takes up the bottom section of your screen. Well, except when you need stats or construction menus, which are presented in separate windows. For this, I'm using HTML popups and referencing the main window with window.opener. Here's an image of what I mean:
Spoiler: image
4.png
I have onsceen buttons to access these menus but I also want to be able to use keys. Example: 'B' for build. That was easy to set up, but once I click 'B', the main window loses focus, so clicking 'B' again does nothing. To fix this I added event listeners to the new windows, which is fine pressing 'B' on any window will now open/close the build menu.

The big issue: once I've clicked 'B' and focus moves over to the other window, if I want to move my character, I have to re-click on the main window! (this is very user-unfriendly. I can't set event listeners on the popups to main window.focus() because popups aren't allowed to steal focus control. Years ago you just had to window.blur() prior to focus, but that has been patched out. Even setting the main window with an alert will not regain focus until you click it!

How I'm managing it right now is by running the main game's functions (move, attack, etc.) THROUGH the popups. An absolutely ridiculous solution.

Does anybody know a way to regain a parent window's focus from a popup? For what it matters, I'm using the most up to date nwjs with chromium.
Hi there!

I'm not too well-versed with all those things you said. But if you are trying to set focus using "window.focus()", are you sure you are in the right context? Meaning, that should work on the RPG maker context, but maybe from this other window(pop up) you created, the context is changed?

I google something and I found this:
[EDIT] Sent the message by accident...

JavaScript:
function showWindow(){
    var gui = require('nw.gui');
    var win = gui.Window.get();
    win.show();
    win.focus();
}

Or maybe, instead of using HTML, you can try to create these pop windows with the Maker itself(PIXI) ?
Hey! Thanks for taking a look.

That code, works for focusing on the newly opened popup, but can't be reversed so that the main window restores focus without a click. Chromium won't allow it >.< As for PIXI, it requires a canvas and a window to operate so can only create popups within the frame of the existing window.

After a very long night, I've given up. I've managed to 'simulate' focus by passing all keystrokes through the popups back to the main window and (with some changing of my popup windows features) nobody would tell the difference. :shrugs:

But thanks again for taking a look.

Original thread: https://forums.rpgmakerweb.com/threads/window-focus-and-window-blur-nerfed-for-security-i-need-a-modern-solution-to-creating-a-pop-under-explanation-below.148611/