Chrome Extension Disappears while clicking outside of its resolution

175 Views Asked by At

Is there anyway that I can make Chrome Extension's window stick in window even while clicking outside of its resolution?

I'm trying to make it Sticky on the window for one simple google login so that I don't need to go back again to click extension to open it.

1

There are 1 best solutions below

0
On

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:

  1. 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.
  2. 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.
  3. 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.