我在manifest.json的"contentScript"注入一段代码dd.js(且"run_at": "document_end","match"也给了对应的条件)。另外"permissions": ["storage","tabs","activeTab","https://*/*" ],应该是没有遗漏的。
现在在dd.js上写:
chrome.tabs.getCurrent(function(tab){
console.log(tab);
} );
//输出:Uncaught TypeError: Cannot read property 'getCurrent' of undefined
这问题我在stackflow上找了很多答案,有人说不能在popup和background上写,不过我这是contentscript上注入的所以应该不是这问题;有人说要用getSelect来写,但这玩意儿不是淘汰了嘛?有人说可以用query来写,但我觉得这好像小题大做了而且试过了也不行。最重要的是实在看不出getcurrent哪里错了。。。。多简单的一个语句啊,为嘛就错了呢。。。