pd1*_*176 4 javascript google-chrome google-chrome-extension
我正在尝试使用chrome.extension.getBackgroundPage函数访问我的扩展程序的后台页面.
但是,我收到以下错误:
未捕获的TypeError:chrome.extension.getBackgroundPage不是函数
我打电话从我的函数bar.js文件,该文件被定义为web_accessible_resource在我manifest.json
我如何使其工作?
的manifest.json
{
"manifest_version": 2,
"name": "XPath Helper",
"version": "1.0.13",
"description": "Extract, edit, and evaluate XPath queries with 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"
]
}
Run Code Online (Sandbox Code Playgroud)
bar.js是一个内部脚本bar.html(不是内容脚本):
// ...
document.addEventListener('DOMContentLoaded',function(){
// previosuly chrome.extension.getBackgroundPage()
chrome.runtime.getBackgroundPage(function(page){
alert("hello");
})
})
Run Code Online (Sandbox Code Playgroud)
content.js
// ...
this.barFrame_ = document.createElement('iframe');
this.barFrame_.src = chrome.extension.getURL('bar.html');
document.body.appendChild(this.barFrame_);
// ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5043 次 |
| 最近记录: |