In window B you set a cookie and in window A you create a setTimeout function that every "x" milliseconds check if there are any new cookie.

Look at this: Javascript communication between browser tabs/windows

Answer from David Ginanni on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › tabs › onActiveChanged
tabs.onActiveChanged - Mozilla - MDN Web Docs
July 17, 2025 - browser.tabs.onActiveChanged.addListener(listener) browser.tabs.onActiveChanged.removeListener(listener) browser.tabs.onActiveChanged.hasListener(listener) ... Adds a listener to this event. ... Stop listening to this event. The listener argument is the listener to remove. ... Check whether listener is registered for this event. Returns true if it is listening, false otherwise. ... The function called when this event occurs.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › tabs › onCreated
tabs.onCreated - Mozilla - MDN Web Docs
July 17, 2025 - browser.tabs.onCreated.addListener(listener) browser.tabs.onCreated.removeListener(listener) browser.tabs.onCreated.hasListener(listener) ... Adds a listener to this event. ... Stop listening to this event. The listener argument is the listener to remove. ... Check whether listener is registered for this event. Returns true if it is listening, false otherwise. ... The function called when this event occurs.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › EventTarget › addEventListener
EventTarget: addEventListener() method - Web APIs | MDN
3 weeks ago - It works on any event target, not just HTML or SVG elements. The method addEventListener() works by adding a function, or an object that implements a handleEvent() function, to the list of event listeners for the specified event type on the EventTarget on which it's called.
🌐
Tom McFarlin
tommcfarlin.com › tab-events-in-bootstrap
Managing Tab Events in Bootstrap 3 | Tom McFarlin
August 26, 2015 - In the markup above, I’ve got a simple unordered list of three tabs the first of which is active as denoted by its classname. This will create a list of navigation options: ... The first of which will be marked as active and the others that will be marked as active when clicked and then will trigger a pane of content to change on the page. Next, I’ll write some JavaScript that will attach an event handler to each of the anchors contained in the above list items that will read the href attribute of the anchor when it has been clicked.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › tabs › onRemoved
tabs.onRemoved - Mozilla - MDN Web Docs
July 17, 2025 - The function called when this event occurs. The function is passed these arguments: ... object. The tab's window ID, and a boolean indicating whether the window is also being closed. See the removeInfo section for more details. ... function handleRemoved(tabId, removeInfo) { console.log(`Tab: ${tabId} is closing`); console.log(`Window ID: ${removeInfo.windowId}`); console.log(`Window is closing: ${removeInfo.isWindowClosing}`); } browser.tabs.onRemoved.addListener(handleRemoved);
🌐
Eloquent JavaScript
eloquentjavascript.net › 15_event.html
Handling Events :: Eloquent JavaScript
Of course, the program has to remember ... the software to feel unresponsive. This approach is called polling. Most programmers prefer to avoid it. A better mechanism is for the system to actively notify the code when an event occurs. Browsers do this by allowing us to register functions as handlers for specific ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › tabs › onActivated
tabs.onActivated - Mozilla - MDN Web Docs
July 17, 2025 - browser.tabs.onActivated.addListener(listener) browser.tabs.onActivated.removeListener(listener) browser.tabs.onActivated.hasListener(listener) ... Adds a listener to this event. ... Stop listening to this event. The listener argument is the listener to remove. ... Check whether listener is registered for this event. Returns true if it is listening, false otherwise. ... The function called when this event occurs.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › Working_with_the_Tabs_API
Work with the Tabs API - Mozilla - MDN Web Docs
March 31, 2026 - It then uses the same listener we discussed earlier so it can act on clicks in tabs.html. ... // Other if conditions... if (e.target.id === "tabs-add-zoom") { callOnActiveTab((tab) => { browser.tabs.getZoom(tab.id).then((zoomFactor) => { // The maximum zoomFactor is 5, it can't go higher if (zoomFactor >= MAX_ZOOM) { alert("Tab zoom factor is already at max!"); } else { let newZoomFactor = zoomFactor + ZOOM_INCREMENT; // If the newZoomFactor is set to higher than the max accepted // it won't change, and does not alert that it's at maximum newZoomFactor = newZoomFactor > MAX_ZOOM ?
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › tabs › onUpdated
tabs.onUpdated - Mozilla - MDN Web Docs
March 31, 2026 - Log changes only when the pinned property of tabs changes for tabs whose url property is matched by https://developer.mozilla.org/* or https://mastodon.social/@mdn where the tab was part of the current browser window when the update event fired: ... const pattern1 = "https://developer.mozilla.org/*"; const pattern2 = "https://mastodon.social/@mdn"; const filter = { urls: [pattern1, pattern2], properties: ["pinned"], windowId: browser.windows.WINDOW_ID_CURRENT, }; function handleUpdated(tabId, changeInfo, tabInfo) { console.log(`Updated tab: ${tabId}`); console.log("Changed attributes: ", changeInfo); console.log("New tab Info: ", tabInfo); } browser.tabs.onUpdated.addListener(handleUpdated, filter);
🌐
Quora
quora.com › JS-How-do-I-detect-when-a-user-clicks-on-a-tab
JS: How do I detect when a user clicks on a tab? - Quora
Answer (1 of 3): There are three methods you can use. I myself would prefer using jQuery for this, but since the question is about JS, I assume vanilla JS is meant. 1. This method doesn’t require to select the specific element. Instead you just add the onclick attrib...
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › apps › develop › ui › controls › tab-view
Tab View - Windows apps | Microsoft Learn
In this configuration, you need to handle the AddTabButtonClick and TabCloseRequested events to enable the functionality. When tabs are added to a TabView, there might eventually be too many tabs to display in your tab strip. In this case, scroll bumpers will appear that let the user scroll the tab strip left and right to access hidden tabs. This example creates a simple TabView along with event handlers to support opening and closing tabs.
🌐
DEV Community
dev.to › j471n › detect-when-users-switch-tabs-using-javascript-3mi3
Detect When Users Switch Tabs using JavaScript - DEV Community
September 13, 2022 - In this article, I'll show you how to find out when users change tabs in browsers using JavaScript. It's going to be fun, it's helpful to see how often the user loses his attention. You can even use it to add the data to the database (it is out of the scope of this article). There are two ways I know how to solve this problem. So, I'll be showing you both of them. In this method, we will use two event listeners focus (when the user focuses on your website or window) and blur (when the user loses focus)