我基本上只是试图获取当前标签网址,如果他们在youtube.com上。我不断收到脚本中的错误。Chrome扩展错误tab.url
Error:
Uncaught TypeError: Cannot call method 'getSelected' of undefined
清单
{
"name": "YouTube Fix",
"version": "0.0.1",
"manifest_version": 2,
"description": "Fix some of the annoying little things in YouTube.",
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"content_scripts": [{
"matches": ["http://www.youtube.com/*"],
"js": ["background.js"],
"run_at": "document_start"
}],
"permissions": ["tabs"]
}
Background.js
//this is what is giving me the error:
chrome.tabs.getSelected(null, function (tab) {
myFunction(tab.url);
});
function myFunction(tablink) {
if (tablink == "http://www.youtube.com") {
window.location = "http://www.youtube.com/feed/subscriptions/u";
}
document.getElementById("comments-textarea").disabled = false;
}
被弃用并不意味着它被删除。 “chrome.tabs.getSelected”在测试后台页面中工作得很好。此外,如果问题是getSelected已被删除,错误将会是“Uncaught TypeError:Object#
@JeffreyYasskin - 我很抱歉,但答案中的哪里说它不再工作? –
说getSelected已被弃用与解决这个问题无关,这个问题不会让作者更接近于工作扩展。评论当然是真实有用的,但这不是一个答案。 –