chrome extension insert content script on browser action

后端 未结 2 1382
青春惊慌失措
青春惊慌失措 2020-12-09 08:37

I am trying to make basically an element highlighter chrome extension. Workflow: - click on browser icon - click on the page - hightlight the element clicked

I am

相关标签:
2条回答
  • 2020-12-09 08:57

    Turns out I could not read the error properly until I saw it in here

    Apparently manifest v2 does not allow you to have inline scripts, so you just need to

    src="path_to_the_file.js"
    
    0 讨论(0)
  • 2020-12-09 09:04

    In extension to @tak3r's answer and @Doug's comment:

    Inline scripts need to be changed to external scripts.

    Move:

    <script>
      chrome.tabs.executeScript(null,{
        code:"document.body.style.backgroundColor='red'"
      });
    </script>
    

    To a new file called main.js and remove the <script></script> tags

    Include the following in the <head></head> of your HTML

    <script type="text/javascript" src="main.js"></script>
    
    0 讨论(0)
提交回复
热议问题