Search code examples
javascriptgoogle-chrome-extension

accessing the current html page from chrome extension


I'm new to chrome extensions. I would like to create a simple chrome extension that popup an alert with the title of the current html page. when I'm performing: alert(document.title) , I'm not getting it because the document object doesn't belong to the page but to the extension script (is it correct?) how do i get the right document object?


Solution

  • You can use the tabs module:

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