0

How do I send some stored data to a script (declared in web_acessible_resources) that I want to inject into a webpage? I've tried to send message from my background script but chrome.extension is not available for use.

manifest.json:

 {
  "manifest_version": 2,

  "name": "Tool",
  "version": "0.0",
  "devtools_page": "devtools.html",
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["contentscript.js"]
  }],
  "background": {
    "scripts": ["background.js"]
  },
  "browser_action": {
    "default_icon": "icon.jpg"
  },
  "web_accessible_resources": [
    "config.js",
    "script.js", 
  ],
  "permissions": [
    "storage"
  ]
}

The config.js contain js configuration to be used by script.js. So in my contentscript.js I have:

var a = document.createElement("script");
a.src = chrome.extension.getURL("config.js");
(document.heade || document.documentElement).appendChild(a);


var s = document.createElement("script");
s.src = chrome.extension.getURL("script.js");
(document.head || document.documentElement).appendChild(s);

What do i need to do in my background.js so that the following is possible inside my config.js?

var myConfig = <some dictionary/json file generated from background.js>
user1948847
  • 955
  • 1
  • 12
  • 27
  • Minor typo, not a cause for the issue: `document.heade` should be `document.head`. – Makyen Jan 16 '17 at 23:42
  • Use DOM events for webpage - content script and normal chrome API for content script - background page. For example: [Call background function of Chrome extension from a site](//stackoverflow.com/a/13779769) – wOxxOm Jan 16 '17 at 23:51
  • Possible duplicate of [Executing code at page-level from Background.js and returning the value](http://stackoverflow.com/questions/26140443/executing-code-at-page-level-from-background-js-and-returning-the-value) – Makyen Jan 17 '17 at 06:03

0 Answers0