By using tabs API you could retrieve windowId
of the window you want to focus on. You could do it only if needed e.g. by using query
method from that API. You could pass url
for example.
If you created a window that you want to be still focused then you have its id already in the hand.
After that, you could use window API update
method in order to draw attention or focus. Take a look at updateInfo
params - focus
and drawAttention
.
The same could be done by using tabs
API. You could pass tabId
and the URL you want to redirect someone.
Now in order to make it work you have a couple of options:
- You can use
setInterval
which would be used to check if the tabId and windowId
you want are active and focus the window/tab you want in another case.
- Because in the MV3 extensions using
setInterval
is not recommended you could use alarms. Please take a look at AlarmCreateInfo
, when
param should help you instead of triggering the alarm periodically.
- You could also use event listeners from both
windows
and tabs
API to listen on tab / window focus change. Then you will be able block the change (from user perspective) by methods I described before.
You should play with all approaches and pick on that suits you, because all of them have some drawback. But don't want to make that comment very long.