MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Browser / switchToTab

Function switchToTab

wvbrowser_ui/controls_ui/tabs.js:47–97  ·  view source on GitHub ↗
(id, updateOnHost)

Source from the content-addressed store, hash-verified

45}
46
47function switchToTab(id, updateOnHost) {
48 if (!id) {
49 console.log('ID not provided');
50 return;
51 }
52
53 // Check the tab to switch to is valid
54 if (!isValidTabId(id)) {
55 return;
56 }
57
58 // No need to switch if the tab is already active
59 if (id == activeTabId) {
60 return;
61 }
62
63 // Get the tab element to switch to
64 var tab = document.getElementById(`tab-${id}`);
65 if (!tab) {
66 console.log(`Can't switch to tab ${id}: element does not exist`);
67 return;
68 }
69
70 // Change the style for the previously active tab
71 if (isValidTabId(activeTabId)) {
72 const activeTabElement = document.getElementById(`tab-${activeTabId}`);
73
74 // Check the previously active tab element does actually exist
75 if (activeTabElement) {
76 activeTabElement.className = 'tab';
77 }
78 }
79
80 // Set tab as active
81 tab.className = 'tab-active';
82 activeTabId = id;
83
84 // Instruct host app to switch tab
85 if (updateOnHost) {
86 var message = {
87 message: commands.MG_SWITCH_TAB,
88 args: {
89 tabId: parseInt(activeTabId)
90 }
91 };
92
93 window.chrome.webview.postMessage(message);
94 }
95
96 updateNavigationUI(commands.MG_SWITCH_TAB);
97}
98
99function closeTab(id) {
100 // If closing tab was active, switch tab or close window

Callers 3

createNewTabFunction · 0.85
closeTabFunction · 0.85
loadTabUIFunction · 0.85

Calls 2

isValidTabIdFunction · 0.85
updateNavigationUIFunction · 0.85

Tested by

no test coverage detected