How to inject inline JS in Chrome V3

Viewed 40

I have a Chrome extension in V2. I am trying to migrate it to Chrome V3. In the code I am trying to append a node using appendChild.

Code snippet I have used to inject the java script to the DOM of page been opened by Browser is as below.

var injectScript = function() {
    var node = document.createElement('script');
    var jscode = '(' + <some code> +  ')();';
    node.innerHTML = jscode;
    document.head.appendChild(node);
};

Changes done in manifest.json for v3

"content_security_policy": {
   extension_pages": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}

Chrome extension is showing below error message. Refused to execute inline script because it violates the following Content Security Policy directive script-src 'self' 'unsafe-eval'. Either the unsafe-inline keyword, a hash or a nonce is required to enable inline execution.

I tried multiple links of stackoverflow, but unable to find any resolution. Does Chrome V3 allows inline script injection ? If not what's the alternative.

0 Answers
Related