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 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Note that this approach requires "tabs" permission, "activeTab" may not be enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.