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