0

I want the current tab url to be display in the pop up after clicking the extension. I have a popup html and popup.js. For testing purpose, I been trying to alert the tab url instead of replacing the html element.

Manifest.json

{
    "manifest_version": 2,
    "name": "first extension",
    "version": "1.0",

    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html",
        "default_title": "Share it!"
    },

    "permissions": [
        "activeTab"
    ]
}

popup.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="popup.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    URL:
    <p>www.blahblah.com</p>
    <form>
        Title:<br />
        <input type="text" name="title"><br />
        Description:<br />
        <textarea rows="4"></textarea><br />
        <button>Get</button>
    </form>
</body>
</html>

popup.js

chrome.tabs.getCurrent(function(tab){
        alert(tab.url);
    }
);

1 Answers1

1

You may want to follow the suggested workaround in this link. Try this query chrome.tabs.query(object queryInfo, function callback) which will get all tabs that have the specified properties, or all tabs if no properties are specified.

chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
    console.log(tabs[0].url);
});

Here another thread which might also help: How to get current URL in Chrome on click of the button

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59