Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:51:40+00:00 2026-05-23T07:51:40+00:00

From my knowledge it is not possible directly by getting tab.url (only possible in

  • 0

From my knowledge it is not possible directly by getting tab.url (only possible in the popup.html) and doing message passing also requires that popup.html be open. Is there anyway to bypass this and get the current page url from background.html?

My best shot was with message passing, which I used this code in background.html

var bg = chrome.extension.getPopupPage(); 
var myURL = bg.myURL; 

then in popup.html I had:

 chrome.tabs.getSelected(null, function(tab) {
    var myURL = tab.url;
})

Anyways the above does’t work at all. Anybody know of a way to do this without having to actually open up the popup?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:51:40+00:00Added an answer on May 23, 2026 at 7:51 am

    chrome.tabs.query is supported from background pages, of course as long as you have the tabs permission. This is the supported route as of Chrome 19.

    chrome.tabs.query({
      active: true,
      currentWindow: true
    }, function(tabs) {
      var tab = tabs[0];
      var url = tab.url;
    });
    

    Note that currentWindow is needed because it would otherwise return the active tab for every window. This should be guaranteed to only return one tab.

    Of course, keep in mind that this is an asynchronous API – you can’t access any data it provides except from within the callback function. You can store values (such as url here) at a higher scope so another function can access it, but that will still only provide the correct result after the callback is executed.


    (The below is my original answer kept for posterity – this method is no longer necessary, requires an always-running background page, and getSelected() is deprecated.)

    First put this in background.html and make the myURL variable global:

    var myURL = "about:blank"; // A default url just in case below code doesn't work
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { // onUpdated should fire when the selected tab is changed or a link is clicked 
        chrome.tabs.getSelected(null, function(tab) {
            myURL = tab.url;
        });
    });
    

    Then run this in popup.html when you want to get the page url:

    chrome.extension.getBackgroundPage().myURL;
    

    So if I were to make that appear inside the popup and I went to Google and clicked your page or browser action, I’ll see http://google.com/webhp in the popup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To my knowledge Nginx can only password protect directories from within the configuration file(s).
It's common knowledge that using System.Diagnostics.Process.Start is the way to launch a url from
I don't know if this is possible or not, or if my limited knowledge
I have basic knowledge of Java's reflection API - therefore, this is not only
For some time I’ve seen employers demanding Sharepoint knowledge from programmers, but I have
Starting from scratch with very little knowledge of .NET, how much ASP.NET should I
I am coming to Objective-C from C# without any intermediate knowledge of C. (Yes,
I'm not sure if this is possible in Delphi. I've looked around and can't
I know LINQ but my knowledge is pretty much only selects, where, orderby and
It is common knowledge that built-in enums in C++ are not typesafe. I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.