1

i am making a Google Chrome extensions that should download mp4 files that are detected on the website page i'm on but i can't run my function that are on my script tags and i can't figure how to fix this. I got 2 errors, both related on the CSP:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-F7oiGRIrds+2B67r3VVNsXI1RXzWT/pYKihh3o3t4mg='), or a nonce ('nonce-...') is required to enable inline execution.

and

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.

Here is my code:

        <header>
            <div class="d_button">
                <a id="download_b" href="files" download="video.mp4">Download</a>
            </div>
        </header>

        <script>
            document.getElementById("download_b").addEventListener("click", search4vid);
            function search4vid();
                const types = /\.(|mp4)/
                const files = performance.getEntriesByType('resource').filter(resource => resource.name.match(types) !== null).reduce((accum, value) => {
                accum[value.name.split('/')[value.name.split('/').length - 1]] = value.name
                return accum}, {})
            document.getElementById('download_b').setAttribute("href",link);
            document.getElementById('download_b').innerHTML = link;
        </script>

My javascript code is surely wrong but i can't test it. The javascript function should activate when clicking on a html text and replace an href="" by the JS variable types to then download it. It may be a little confusing and it is to me too but i'm trying my best. Thanks

Max
  • 11
  • 3
  • What is this code part of ? Is it in a pop-up window, a background script or is it a content script ? – Titus Oct 31 '21 at 18:19
  • Hi! Uhh i mean my extensions only got 1 pop-up actually so i think it is just a pop-up window?? Sorry if i cant answer you correctly its my first time in chrome extensions... This part of code is from my "menu"? – Max Oct 31 '21 at 18:29
  • In that case, one of the problems is that you cannot use a ` – Titus Oct 31 '21 at 18:31
  • The other problem is that you cannot access the content of a website from the code of a pop-up, you'll need a [content script](https://developer.chrome.com/docs/extensions/mv3/content_scripts/) for that. – Titus Oct 31 '21 at 18:32
  • >"In that case, one of the problems is that you cannot use a no? – Max Oct 31 '21 at 18:36
  • I didn't explain that correctly, you can use `` but you cannot use a ` – Titus Oct 31 '21 at 18:40
  • Alright i get it, thanks you a lot for helping me :D – Max Oct 31 '21 at 20:35
  • This question should be opened again. The linked answers no longer apply as they are both over 8 years old and written for Manifest V2, which is now deprecated. – Andrew Toups Jun 23 '22 at 22:49

0 Answers0