@@ -496,24 +496,6 @@ async function processMessage(request, sender) {
496496 }
497497}
498498
499- /**
500- * Ensures the parameter is a number.
501- * @param {string|number } param - The parameter to clean.
502- * @returns {number } - The cleaned parameter.
503- */
504- function cleanParameter ( param ) {
505- if ( typeof param === 'number' ) {
506- return param ;
507- }
508- if ( param === 'false' ) {
509- return false ;
510- }
511- if ( param === 'true' ) {
512- return true ;
513- }
514- return parseInt ( param , 10 ) ;
515- }
516-
517499function createShortcutsWindow ( ) {
518500 chrome . tabs . create ( { url : 'chrome://extensions/configureCommands' } ) ;
519501}
@@ -928,21 +910,6 @@ async function focusWindow(windowId) {
928910 await chrome . windows . update ( windowId , { focused : true } ) ;
929911}
930912
931- async function focusOrLoadTabInWindow ( window , tabUrl ) {
932- let match = false ;
933- for ( const tab of window . tabs || [ ] ) {
934- if ( getEffectiveTabUrl ( tab ) === tabUrl ) {
935- await chrome . tabs . update ( tab . id , { active : true } ) ;
936- match = true ;
937- break ;
938- }
939- }
940-
941- if ( ! match ) {
942- await chrome . tabs . create ( { url : tabUrl , active : true } ) ;
943- }
944- }
945-
946913/**
947914 * Saves a new session from the specified window.
948915 *
@@ -1253,6 +1220,49 @@ function moveTabToWindow(tab, windowId) {
12531220
12541221// Module-level helper functions.
12551222
1223+ /**
1224+ * Ensures the parameter is a number.
1225+ * @param {string|number } param - The parameter to clean.
1226+ * @returns {number } - The cleaned parameter.
1227+ */
1228+ function cleanParameter ( param ) {
1229+ if ( typeof param === 'number' ) {
1230+ return param ;
1231+ }
1232+ if ( param === 'false' ) {
1233+ return false ;
1234+ }
1235+ if ( param === 'true' ) {
1236+ return true ;
1237+ }
1238+ return parseInt ( param , 10 ) ;
1239+ }
1240+
1241+ /**
1242+ * Searches for a tab with a specific URL within a given window.
1243+ * If a matching tab is found, it is brought into focus.
1244+ * If no matching tab is found, a new tab with the specified URL is created and activated.
1245+ * Note: The new tab is created in the current window, not necessarily the one passed as a parameter.
1246+ *
1247+ * @param {chrome.windows.Window } window The window object to search for the tab in. It should contain a `tabs` array.
1248+ * @param {string } tabUrl The URL of the tab to find or create.
1249+ * @returns {Promise<void> } A promise that resolves once the tab is focused or created.
1250+ */
1251+ async function focusOrLoadTabInWindow ( window , tabUrl ) {
1252+ let match = false ;
1253+ for ( const tab of window . tabs || [ ] ) {
1254+ if ( getEffectiveTabUrl ( tab ) === tabUrl ) {
1255+ await chrome . tabs . update ( tab . id , { active : true } ) ;
1256+ match = true ;
1257+ break ;
1258+ }
1259+ }
1260+
1261+ if ( ! match ) {
1262+ await chrome . tabs . create ( { url : tabUrl , active : true } ) ;
1263+ }
1264+ }
1265+
12561266/**
12571267 * Gets the effective URL of a tab, preferring pendingUrl for loading tabs.
12581268 * @param {chrome.tabs.Tab } tab The tab object to get the effective URL from.
0 commit comments