H
H
habrdima2015-03-23 17:20:22
JavaScript
habrdima, 2015-03-23 17:20:22

Adding code to a site using chrome.tabs.executeScript?

chrome.tabs.executeScript() method; I can add my code to the site to the existing tags, for example style or innerHTML, but only to the existing ones, I can’t create and add a new tag in it, is it not possible or am I doing something wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2015-03-23
@BuriK666

chrome.webNavigation.onDOMContentLoaded.addListener(function (details) {
  if (details.frameId == 0) {
      chrome.tabs.executeScript(details.tabId, {
        runAt:'document_start',
        file: 'script.js'
    });
  }
})

script.js:
var el = document.createElement('div');
el.innerText = "Hell world!";
document.body.appendChild(el);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question