我正在尝试从Chrome扩展程序中访问plug.dj API,但每次我输入API.bar()
时,它都会给我:
未捕获的ReferenceError:未定义API
我使用以下manifest.json
{
"content_scripts": [ {
"js": [
"jquery.js",
"lastfm.api.md5.js",
"lastfm.api.js",
"script.js"
],
"css": [ "LastFMLink.css" ],
"matches": [
"http://plug.dj/*",
"http://plug.dj/*/*"
],
"run_at": "document_end"
}
],
"name": "Plug.Dj VS last.Fm",
"description": "Implement information about the artist",
"icons": { "16": "cookie.png", "48": "cookie.png", "128": "cookie.png" },
"permissions": [
"http://plug.dj/*",
"http://plug.dj/*/*"
],
"version": "1.0.0",
"web_accessible_resources": ["script.js"],
"manifest_version": 2
}
任何人都知道我可能做错了什么?还是忘了?
答案 0 :(得分:0)
等待网站加载完成。看:
function init() {
//Write your code here
}
function cinit() {
if (typeof API == "object" && API.getVolume() != undefined) {
clearInterval(loadClock);
init();
return 1;
} else {
return 0;
}
}
var loadClock = setInterval(cinit, 500);