Google chrome extension 如何在chrome扩展中访问GoogleMapAPI。未捕获引用错误,未定义google
我正在尝试创建一个chrome扩展。 这是我的密码。 manifest.jsonGoogle chrome extension 如何在chrome扩展中访问GoogleMapAPI。未捕获引用错误,未定义google,google-chrome-extension,Google Chrome Extension,我正在尝试创建一个chrome扩展。 这是我的密码。 manifest.json { "name": "MyExtension", "minimum_chrome_version": "10.0", "version": "1.1", "description": "Extends the Developer Tools", "devtools_page": "devtools.html", "manifest_version": 2, "permissions":
{
"name": "MyExtension",
"minimum_chrome_version": "10.0",
"version": "1.1",
"description": "Extends the Developer Tools",
"devtools_page": "devtools.html",
"manifest_version": 2,
"permissions": ["activeTab",
"<all_urls>",
"https://google.com/*"
],
"background": {
"scripts": ["bg.js"]
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*","http://maps.googleapis.com/maps/api/js?sensor=false","<all_urls>"],
"js": ["content_script.js"],
"run_at": "document_start",
"all_frames": true
}]
}
content\u script.js
chrome.devtools.inspectedWindow.eval("setRedSelectedElement($0)",{ useContentScriptContext: true });
var ownerdocument;
function setRedSelectedElement(el) {
ownerdocument= el.ownerDocument;
ownerDocument.body.style.backgroundColor = "**red**";
alert("style updated ");
var latlng = new google.maps.LatLng(26.449895, 74.639916);
alert("success -- "+latlng);
}
在新的google.map.LatLng执行中,扩展失败。
未捕获的引用错误::未定义google
扩展如何访问GoogleAPI 你的内容脚本定义很奇怪。只需使用
“matches”:“
而不是指定”
以及其他内容,这是没有意义的。“permissions”
键也是如此。问题是您定义了要在面板中运行的Google Maps API脚本,但您的内容脚本希望它在面板中运行。但是,内容脚本与您的面板无关。您需要在内容脚本中运行Google Maps API。我不确定使用远程文件是否可以执行此操作,您必须将脚本嵌入到扩展名中(我不确定Google Maps是否允许这样做,您应该检查一下),然后将其添加到内容脚本定义中的“js”
数组键中。
var ownerdocument;
function setRedSelectedElement(el) {
ownerdocument= el.ownerDocument;
ownerDocument.body.style.backgroundColor = "**red**";
alert("style updated ");
var latlng = new google.maps.LatLng(26.449895, 74.639916);
alert("success -- "+latlng);
}