accessing the current html page from chrome extension

后端 未结 4 1712
一向
一向 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:45

    Content scripts are the easiest way to go:

    Expand your manifest file with this code:

    ...
    "content_scripts": [
      {
      "matches": ["http://urlhere/*"],
      "js": ["contentscript.js"]
      }
    ],
    ...
    

    Content script (automatically executed on each page as mentioned at matches at the manifest file):

    alert(document.title)
    

    The advantage of using content scripts over chrome.extension.* methods is that your extension doesn't require scary permissions, such as tabs.


    See also:

    • Developer's guide
    • Content scripts
    • Background pages

提交回复
热议问题