<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TechBlueprints]]></title><description><![CDATA[Welcome to TechBlueprints Dive into tech guides, tutorials, and fun projects. Whether you’re learning or exploring, we’re here to inspire and support your tech ]]></description><link>https://techblueprints.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 06:00:54 GMT</lastBuildDate><atom:link href="https://techblueprints.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Create a Chrome Extension to Retrieve URLs of All Open Tabs]]></title><description><![CDATA[Introduction
Have you ever needed to get the URLs of all your open tabs in Chrome? Whether you're a developer, researcher, or just a heavy browser user, having a simple way to retrieve and manage your open tab URLs can be incredibly useful. In this t...]]></description><link>https://techblueprints.hashnode.dev/how-to-create-a-chrome-extension-to-retrieve-urls-of-all-open-tabs</link><guid isPermaLink="true">https://techblueprints.hashnode.dev/how-to-create-a-chrome-extension-to-retrieve-urls-of-all-open-tabs</guid><dc:creator><![CDATA[Vaibhav Gagneja]]></dc:creator><pubDate>Sun, 30 Mar 2025 15:27:15 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Have you ever needed to <strong>get the URLs of all your open tabs in Chrome</strong>? Whether you're a developer, researcher, or just a heavy browser user, having a simple way to retrieve and manage your open tab URLs can be incredibly useful. In this tutorial, I'll walk you through creating a <strong>Chrome extension</strong> that fetches and displays the URLs of all open tabs. By the end of this guide, you'll have a fully functional extension that you can customize and expand upon as needed.</p>
<h2 id="heading-requirements">Requirements</h2>
<p>Before we start, ensure you have the following:</p>
<ul>
<li><p>A basic understanding of HTML, JavaScript, and JSON.</p>
</li>
<li><p>Google Chrome installed on your computer.</p>
</li>
</ul>
<h2 id="heading-step-by-step-guide">Step-by-Step Guide</h2>
<h3 id="heading-step-1-set-up-your-project">Step 1: Set Up Your Project</h3>
<ul>
<li><p><strong>Create the Project Folder:</strong> Create a new folder on your computer. Name it something like <code>GetTabsURLs</code>.</p>
</li>
<li><p><strong>Create</strong><code>manifest.json</code>: Inside the <code>GetTabsURLs</code> folder, create a file named <code>manifest.json</code> and add the following content:</p>
<pre><code class="lang-json">  {
    <span class="hljs-attr">"manifest_version"</span>: <span class="hljs-number">3</span>,
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Get Open Tabs URLs"</span>,
    <span class="hljs-attr">"version"</span>: <span class="hljs-string">"1.0"</span>,
    <span class="hljs-attr">"permissions"</span>: [<span class="hljs-string">"tabs"</span>],
    <span class="hljs-attr">"background"</span>: {
      <span class="hljs-attr">"service_worker"</span>: <span class="hljs-string">"background.js"</span>
    },
    <span class="hljs-attr">"action"</span>: {
      <span class="hljs-attr">"default_popup"</span>: <span class="hljs-string">"popup.html"</span>
    }
  }
</code></pre>
<ul>
<li><p>The <code>manifest.json</code> file is like the blueprint for your Chrome extension. It tells Chrome what your extension does, what permissions it needs, and which files to use.</p>
</li>
<li><p><code>manifest_version</code>: This specifies the version of the manifest file format. Version 3 is the latest and most current.</p>
</li>
<li><p><code>name</code>: The name of your extension. This is what users will see.</p>
</li>
<li><p><code>version</code>: The version of your extension. It helps in managing updates.</p>
</li>
<li><p><code>permissions</code>: This is where you ask for permission to access browser tabs. Without this, your extension won't be able to get the URLs.</p>
</li>
<li><p><code>background</code>: This section specifies the background script that runs behind the scenes. In our case, <code>background.js</code> will handle the functionality when the extension icon is clicked.</p>
</li>
<li><p><code>action</code>: Defines the UI of your extension’s icon. The <code>default_popup</code> points to the HTML file that will show up when users click the icon.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-2-create-the-background-script">Step 2: Create the Background Script</h3>
<ul>
<li><p><strong>Create</strong><code>background.js</code>: In the same folder, create a file named <code>background.js</code> and add the following content:</p>
<pre><code class="lang-javascript">  chrome.action.onClicked.addListener(<span class="hljs-function">(<span class="hljs-params">tab</span>) =&gt;</span> {
    chrome.tabs.query({}, <span class="hljs-function">(<span class="hljs-params">tabs</span>) =&gt;</span> {
      <span class="hljs-keyword">let</span> urls = tabs.map(<span class="hljs-function"><span class="hljs-params">tab</span> =&gt;</span> tab.url);
      <span class="hljs-built_in">console</span>.log(urls);
      alert(urls.join(<span class="hljs-string">'\n'</span>));
    });
  });
</code></pre>
<ul>
<li><p>This is the script that runs in the background of your extension. It listens for clicks on your extension’s icon and then performs actions accordingly.</p>
</li>
<li><p><code>chrome.action.onClicked.addListener</code>: This listens for clicks on the extension icon. When the icon is clicked, the provided function is executed.</p>
</li>
<li><p><code>chrome.tabs.query({}, (tabs) =&gt; {...})</code>: Queries all open tabs in the browser. The empty object <code>{}</code> means we're interested in all tabs.</p>
</li>
<li><p><a target="_blank" href="http://tabs.map"><code>tabs.map</code></a><code>(tab =&gt; tab.url)</code>: Extracts the URL from each tab object.</p>
</li>
<li><p><code>console.log(urls)</code>: Logs the URLs to the console, which can be useful for debugging.</p>
</li>
<li><p><code>alert(urls.join('\n'))</code>: Displays the URLs in a pop-up alert, each on a new line.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-3-create-the-popup-interface">Step 3: Create the Popup Interface</h3>
<ul>
<li><p><strong>Create</strong><code>popup.html</code>: In the <code>GetTabsURLs</code> folder, create a file named <code>popup.html</code> with the following content:</p>
<pre><code class="lang-xml">  <span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Get Open Tabs URLs<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"getTabs"</span>&gt;</span>Get Tabs URLs<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pre</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"output"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">pre</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"popup.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<ul>
<li><p>This is the HTML file that creates the user interface for your extension’s popup.</p>
</li>
<li><p><code>&lt;button id="getTabs"&gt;Get Tabs URLs&lt;/button&gt;</code>: A button users will click to fetch the URLs.</p>
</li>
<li><p><code>&lt;pre id="output"&gt;&lt;/pre&gt;</code>: A <code>pre</code> element where the URLs will be displayed in a preformatted text style.</p>
</li>
<li><p><code>&lt;script src="popup.js"&gt;&lt;/script&gt;</code>: Links to the JavaScript file that will handle button clicks and update the output.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-4-create-the-popup-script">Step 4: Create the Popup Script</h3>
<ul>
<li><p><strong>Create</strong><code>popup.js</code>: Finally, create a file named <code>popup.js</code> with the following content:</p>
<pre><code class="lang-javascript">  <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'getTabs'</span>).addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function">() =&gt;</span> {
    chrome.tabs.query({}, <span class="hljs-function">(<span class="hljs-params">tabs</span>) =&gt;</span> {
      <span class="hljs-keyword">let</span> urls = tabs.map(<span class="hljs-function"><span class="hljs-params">tab</span> =&gt;</span> tab.url);
      <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'output'</span>).textContent = urls.join(<span class="hljs-string">'\n'</span>);
    });
  });
</code></pre>
<ul>
<li><p>This script controls the behavior of the popup interface.</p>
</li>
<li><p><code>document.getElementById('getTabs')</code>: Selects the button element by its ID.</p>
</li>
<li><p><code>.addEventListener('click', ...)</code>: Adds a click event listener to the button.</p>
</li>
<li><p><code>chrome.tabs.query({}, (tabs) =&gt; {...})</code>: Queries all open tabs.</p>
</li>
<li><p><a target="_blank" href="http://tabs.map"><code>tabs.map</code></a><code>(tab =&gt; tab.url)</code>: Maps the tabs to their URLs.</p>
</li>
<li><p><code>document.getElementById('output').textContent = urls.join('\n')</code>: Updates the <code>pre</code> element with the list of URLs, separated by new lines.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-5-load-and-test-your-extension">Step 5: Load and Test Your Extension</h3>
<ul>
<li><p><strong>Load the Extension in Chrome:</strong></p>
<ul>
<li><p>Open Chrome and navigate to <code>chrome://extensions/</code>.</p>
</li>
<li><p>Enable <code>Developer mode</code> by toggling the switch in the top right corner.</p>
</li>
<li><p>Click the <code>Load unpacked</code> button and select the <code>GetTabsURLs</code> folder.</p>
</li>
</ul>
</li>
<li><p><strong>Use the Extension:</strong></p>
<ul>
<li><p>After loading the extension, you should see its icon appear in the toolbar (it might be under the puzzle piece icon).</p>
</li>
<li><p>Click on the extension icon to open the popup.</p>
</li>
<li><p>In the popup, click the <code>Get Tabs URLs</code> button.</p>
</li>
<li><p>The URLs of all open tabs will be displayed in the <code>pre</code> element in the popup.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-optional">Optional:</h2>
<h3 id="heading-adding-an-icon">Adding an Icon</h3>
<p>If you want to add an icon to your extension:</p>
<ol>
<li><p><strong>Create an</strong><code>icons</code> folder: Inside your <code>GetTabsURLs</code> folder, create a new folder named <code>icons</code>.</p>
</li>
<li><p><strong>Add Icon Images:</strong> Add your icon images (e.g., <code>icon.png</code>) in different sizes (e.g., 16x16, 48x48, 128x128).</p>
</li>
<li><p><strong>Update</strong><code>manifest.json</code>: Update your <code>manifest.json</code> to include the icons:</p>
<pre><code class="lang-json"> {
   <span class="hljs-attr">"manifest_version"</span>: <span class="hljs-number">3</span>,
   <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Get Open Tabs URLs"</span>,
   <span class="hljs-attr">"version"</span>: <span class="hljs-string">"1.0"</span>,
   <span class="hljs-attr">"permissions"</span>: [<span class="hljs-string">"tabs"</span>],
   <span class="hljs-attr">"background"</span>: {
     <span class="hljs-attr">"service_worker"</span>: <span class="hljs-string">"background.js"</span>
   },
   <span class="hljs-attr">"action"</span>: {
     <span class="hljs-attr">"default_popup"</span>: <span class="hljs-string">"popup.html"</span>,
    <span class="hljs-attr">"default_icon"</span>: {
             <span class="hljs-attr">"16"</span>: <span class="hljs-string">"dog_1998627.png"</span>,
             <span class="hljs-attr">"48"</span>: <span class="hljs-string">"dog_1998627 (1).png"</span>,
             <span class="hljs-attr">"128"</span>: <span class="hljs-string">"dog_1998627 (2).png"</span>
         }
     },
     <span class="hljs-attr">"icons"</span>: {
         <span class="hljs-attr">"16"</span>: <span class="hljs-string">"dog_1998627.png"</span>,
         <span class="hljs-attr">"48"</span>: <span class="hljs-string">"dog_1998627 (1).png"</span>,
         <span class="hljs-attr">"128"</span>: <span class="hljs-string">"dog_1998627 (2).png"</span>
     }
 }
</code></pre>
</li>
</ol>
<h3 id="heading-summary">Summary</h3>
<ul>
<li><p><code>manifest.json</code>: Sets up the extension’s basic information and permissions.</p>
</li>
<li><p><code>background.js</code>: Handles clicks on the extension icon and retrieves tab URLs.</p>
</li>
<li><p><code>popup.html</code>: Creates the visual layout of the popup.</p>
</li>
<li><p><code>popup.js</code>: Manages interactions within the popup, like fetching and displaying URLs.</p>
</li>
</ul>
<p>By understanding each part of the code, you'll be able to modify and enhance the extension to fit your needs. Happy coding!</p>
<p>You can find the full code, just click on this <a target="_blank" href="https://github.com/VaibhavGagneja/GetChromeUrlsExtention">link</a>.</p>
]]></content:encoded></item></channel></rss>