Skip to content

Commit 2c7fcc1

Browse files
How to get the current tab?
1 parent 8ae37e0 commit 2c7fcc1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

05 Build a Chrome Extension/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ if (leadsFromLocalStorage) {
1414
const tabs = [{ url: "https://www.linkedin.com/in/junaidhassan19/" }];
1515

1616
tabBtn.addEventListener("click", function () {
17-
// Save the url instead of logging it out
17+
// Grab the URL of the current tab!
18+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
19+
// since only one tab should be active and in the current window at once
20+
// the return variable should only have one entry
21+
let activeTab = tabs[0];
22+
let activeTabId = activeTab.id; // or do whatever you need
23+
});
1824
myLeads.push(tabs[0].url);
1925
localStorage.setItem("myLeads", JSON.stringify(myLeads));
2026
render(myLeads);

0 commit comments

Comments
 (0)