1

manifest.json

{
    "manifest_version": 3,
    "name": "Inject Scripts",
    "version": "1.0",
    "content_scripts": [{
        "matches": [
            "*://*/*"
        ],
        "run_at": "document_end",
        "js": [
            "content.js"
        ]
    }],
    "web_accessible_resources": [{
        "resources": [
            "every site .js"
        ],
        "matches": []
    }]
}

content.js

document.head.insertAdjacentHTML('beforeend', ˋ<script src="${chrome.runtime.getURL('every site .js')}"></script>ˋ)

every site .js

console.log('injected')

<script> was inserted to <head> successful with the src="chrome-extension://<extension ID>/every site .js" attribute but there is neither console.log output nor Error message.

I installed my extension locally by enabling "Developer mode" and "Load unpacked" in "chrome://extensions/".

Do I need to specify "permissions" in manifest.json?

Minh Cường
  • 347
  • 1
  • 15
  • 1
    Neither insertAdjacentHTML nor innerHTML run `script` elements. This is intentional. Use document.createElement and appendChild, example: [link](https://stackoverflow.com/a/9517879). – wOxxOm Mar 01 '21 at 16:22
  • Thanks @wOxxOm, I missed that info. – Minh Cường Mar 01 '21 at 17:38

0 Answers0