Chrome Extension lastFocusedWindow not changing when clicking on popups in different windows

I’m trying to get all the tabs in the current window when the user clicks my popup. I know that chrome.windows.getCurrent() won’t always work because that’s the window where code is executing.

So I tried chrome.windows.getLastFocused() but then I realized I could do the same thing directly on the tabs

chrome.tabs.query({lastFocusedWindow: true}, (tabs)=>{
    tabs.forEach(function(tab){
        console.log(tab.title)
    })
})

The Problem
When I have multiple multiple windows open and I click on the extension icon to open my popup, lastFocusedWindow doesn’t seem to change.
I have event handlers that are currently just firing to log the tabs in the current window when the popup loads and also listening for clicks anywhere inside the popup.

Example: I have 2 windows

  1. Click the popup icon in window1 (correctly identified tabs in window1)
  2. Click the popup icon in window2 (correctly identified tabs in window2)
  3. Click inside the popup content on window1 (still thinks I’m in window2 and shows tabs for window 2)

I guess somehow when I click directly on a popup, Chrome doesn’t see that as a focus change and I don’t know what to do.

My workaround/hack is to use window.close() in my popup after they click event happens so that it’s less likely for multiple popups to be open at once but it doesn’t complete solve the issue because they can click to open the popup but then click in another window to open another popup which leaves the 1st popup open.