javascript - chrome.extension.getBackgroundPage is undefined in an extension page in an iframe -
i trying access extension's background page using chrome.extension.getbackgroundpage function.
however, following error:
uncaught typeerror: chrome.extension.getbackgroundpage not function
i calling function bar.js file defined web_accessible_resource in manifest.json
how make work?
manifest.json
{   "manifest_version": 2,   "name": "xpath helper",   "version": "1.0.13",   "description": "extract, edit, , evaluate xpath queries ease.",   "background": {     "page": "background.html"   },   "content_scripts": [     {       "matches": ["<all_urls>"],       "css": ["content.css"],       "js": ["content.js"]     }   ],   "permissions": ["http://*/", "tabs", "identity", "identity.email"],   "icons": {     "32": "static/icon32.png",     "48": "static/icon48.png",     "128": "static/icon128.png"   },   "web_accessible_resources": [     "bar.css",     "bar.html",     "bar.js"   ] }   bar.js script inside bar.html (not content script):
// ...  document.addeventlistener('domcontentloaded',function(){   // previosuly chrome.extension.getbackgroundpage()   chrome.runtime.getbackgroundpage(function(page){     alert("hello");   })   })   content.js
// ...    this.barframe_ = document.createelement('iframe');   this.barframe_.src = chrome.extension.geturl('bar.html');    document.body.appendchild(this.barframe_);  // ...      
most extension apis can only used if page runs in extension process, i.e. top-level frame non-sandboxed chrome-extension: page.
chrome-extension:-frames in non-extension process can access extension apis available content scripts , web pages. , unlike content scripts, can use web platform apis @ extension's origin. example, if use localstorage in content script, dom storage of page content script runs accessed. if use localstorage in chrome-extension: page, you'll extension's storage.
if want access functionality of background page in frame, use extension messaging apis communicate between frame , background page.
Comments
Post a Comment