1

I am making a chrome extension that inserts multiple css and javascript files. I was previously using content scripts but now I want to insert the script and css onClick. I tried just injecting my main script script.js in my background and keeping the rest of my css files associated with this script in my content script section in manifest. However, when I tried this in my extension it did not work. Should I execute and insert all my content and css in my background and if so in what order because one script or css has to be inserted or executed inside another.

I looked at " Injecting multiple scripts through executeScript in Google Chrome" however I don't know if their is a easier way in my situation and I do not know if that articles applies to css.

Here's part of my manifest:

"content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "css": ["styles.css", "tipped.css"],
      "js": ["jquery-1.9.1.js", "jquery-highlight1.js", "spinners.min.js", "tipped.js","script.js"],
      "run_at": "document_end"
    }
  ],
  "permissions":[
    "activeTab"

  ],

Here is my background script:

chrome.browserAction.onClicked.addListener(function(activeTab) {
    chrome.tabs.executeScript(null, {file: "script.js"});

  });
Hans.Gundlach
  • 431
  • 1
  • 6
  • 11
  • As I understand it the `chrome.tabs.executeScript` needs to be called from the content script as the background script is isolated from the DOM and unable to start this injected script. I am surprised it does not throw an error. – Blindman67 Nov 20 '15 at 21:22
  • 1
    @Blindman67, this function is not available in content scripts, the OP is doing it correctly. – wOxxOm Nov 20 '15 at 21:49
  • 1
    Possible duplicate of [Injecting multiple scripts through executeScript in Google Chrome](http://stackoverflow.com/questions/21535233/injecting-multiple-scripts-through-executescript-in-google-chrome) – wOxxOm Nov 20 '15 at 21:50
  • I looked at " Injecting multiple scripts through executeScript in Google Chrome" however I don't know if their is a easier way in my situation and I do not know if that articles applies to css. I will post this above – Hans.Gundlach Nov 21 '15 at 02:42

0 Answers0