Communication between ContentScript.js and Chrome Extension

后端 未结 1 851
南旧
南旧 2020-12-04 03:48

I simply want to send the current tab url to my extension:

Following is my manifest.json

{
 \"name\": \"DocUrlExtention\",
 \"version\": \"1.0\",
 \"         


        
相关标签:
1条回答
  • 2020-12-04 04:27

    Your manifest file contains "manifest_version": 2,, which enables the Content Security Policy. By default, Inline JavaScript will not be executed. And, there is no way to relax the CSP such that inline JavaScript is allowed.

    You've got two options:

    1. Remove "manifest_version": 2 (which disabled the default CSP).
    2. Move the inline JavaScript to an external file.

    The second method is recommended, and also suggested in your code...

    ...
    <!-- JavaScript and HTML must be in separate files for security. -->
    <!--<script src="popup.js"></script>-->
    </head>
    ...
    

    PS. The Dev tools for the pop-up can be opened by right-clicking on the browser action icon, and selecting the last option, "Inspect popup".

    0 讨论(0)
提交回复
热议问题