S
S
Stepgor2020-08-18 10:37:40
JavaScript
Stepgor, 2020-08-18 10:37:40

How to make code work in extension context?

The task is as follows:

1. There is a content_script that works on each page and its task is to load js code from a remote server, and then insert the script into the tag

function AddScriptToPage(code, name) {
    let script = document.createElement('script')
    script.setAttribute('type', 'text/javascript')
    script.setAttribute('hash', 'sha256-CihokcEcBW4atb/CW/XWsvWwbTjqwQlE9nj9ii5ww5M=')
    script.setAttribute('d-name', name)
    script.innerText = code
    document.querySelector('body').append(script)
}

2. I need to make this code work in the extension context, how can I do it?

I also tried without content_script, via executeScript. The same request to the remote server, but from the background and the subsequent injection into all pages, but with this SPA approach, this does not work well, since onUpdated fires every time a new page is requested

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question