From: Bill Erickson <berickxx@gmail.com> Date: Thu, 9 Dec 2021 18:48:22 +0000 (-0500) Subject: LP1954301 Simplify the tab name logic X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5a9e08227da9d997013884780663f0a4dc2c0d2a;p=working%2FHatch.git LP1954301 Simplify the tab name logic Signed-off-by: Bill Erickson <berickxx@gmail.com> Signed-off-by: Michele Morgan <mmorgan@noblenet.org> --- diff --git a/extension/app/extension.js b/extension/app/extension.js index affb361860..4ed72ac727 100644 --- a/extension/app/extension.js +++ b/extension/app/extension.js @@ -85,29 +85,11 @@ function onNativeMessage(message) { /** * Called when our content script opens connection to this extension. */ -var portCounter = 0; // Additional tab name differentiation chrome.runtime.onConnect.addListener(function(port) { - // When a new tab connects, it has no custom name. Since a tab - // with the same tab number can connect multiple times -- sometimes - // in an unexpected order -- give each port a unique name. This - // name will persist for the life of the connected port object. - // - // The port name can normally be any string, but our Java backend - // currently expects a Long (numeric) value, so format the port name - // as the tab number, followed by up to 12 zeroes, followed by our - // auto-increment. This can accommodate more than trillion unique - // tab identifiers before the browser has to be restarted. - // - // TODO: teach the Java backend to treat "msgid" as a String - // instead of a Long so we can use tab names like: - // port.name = tabNumber + "-" + increment++; - if (port.name == "") { - let base = (port.sender.tab.id + "").padEnd(12, "0"); - port.name = Number(base) + portCounter++; - } - - var tabId = port.name; + // Apply a random unique name to each newly connected port. + // This name will persist for the life of the port object. + let tabId = port.name = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER - 1); browserPorts[tabId] = port;