You can focus the popup from the Chrome extension

I have a Chrome extension that does window.open () when the extension icon is clicked. (It cannot use the traditional Chrome pop-up extension due to an unrelated error in Chrome). I am wondering if there is a way to focus the popup if it is already open. Chrome disables window.focus (), but I thought there might be a way to do this in the Chrome extension.

Update: For anyone interested, this is the code I used on my page:

var popupId; // When the icon is clicked in Chrome chrome.browserAction.onClicked.addListener(function(tab) { // If popupId is undefined then there isn't a popup currently open. if (typeof popupId === "undefined") { // Open the popup chrome.windows.create({ "url": "index.html", "type": "popup", "focused": true, "width": 350, "height": 520 }, function (popup) { popupId = popup.id; }); } // There currently a popup open else { // Bring it to the front so the user can see it chrome.windows.update(popupId, { "focused": true }); } }); // When a window is closed chrome.windows.onRemoved.addListener(function(windowId) { // If the window getting closed is the popup we created if (windowId === popupId) { // Set popupId to undefined so we know the popups not open popupId = undefined; } }); 
+6
source share
1 answer

Instead of using window.open (), use Chromes chrome.windows.create ... http://code.google.com/chrome/extensions/windows.html#method-create
... then in the callback you can write its window.id, and then anytime you want to focus, you can use chrome.windows.update.

+8
source

Source: https://habr.com/ru/post/906739/


All Articles