accessing the current html page from chrome extension

后端 未结 4 1694
一向
一向 2021-01-01 19:28

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: ale

4条回答
  •  迷失自我
    2021-01-01 19:59

    For what you're doing all you need to do is this

    chrome.tabs.executeScript({
        code: 'alert(document.title)'
    })
    

    Chrome.tabs.executeScript allows you to run JavaScript in the current page instead of in the extension. So this works just fine but if you want to use the name of the page later in a more complex extension than I would just do what pimvdb did

提交回复
热议问题