chrome.tabs.getSelected未定义在使用清单版本2的最新chrome上? [英] chrome.tabs.getSelected is undefined on latest chrome that uses manifest version 2?
问题描述
我试图创建一个插件,它使用 chrome.tabs.getSelected
来查找当前URL,
下面我附上一个最简单的例子,当按下任意键时,会弹出一个对话框,但它一直告诉我 chrome.tabs.getSelected
未定义:
清单文件:
{
content_scripts:[
{
matches:[http:// * / *,https:// * / *],
js:[main.js]
$ b $manifest_version:2,
description:XX,
图标:{
128:图标bng,
16:button.png,
32:button.png,
48:icon.png
} ,
name:XX,
permissions:[tabs,http:// * / *,https:// * / *],
version:1.2
}
和main.js:
window.addEventListener(keyup,function(e) {
chrome.tabs.getSelected(null,function(tab){// undefined
alert(tab.url);
});
},false);
Chromium版本: 编辑 我现在真的不明白,tabs.query也不行。 编辑:抱歉,刚刚意识到你不能在内容脚本中使用 I'm trying to create a plugin, that uses Below I attached a minimal example, when any key is pressed, a dialog will popup, but it kept telling me Manifest file: And main.js: Chromium version: EDIT I really don't get it now, tabs.query doesn't work either. EDIT: Sorry, just realized you can't use 这篇关于chrome.tabs.getSelected未定义在使用清单版本2的最新chrome上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!版本21.0.1180.89(154005)$ c $
窗口.addEventListener(keyup,function(e){
chrome.tabs.query({active:true},function(tab){
alert(tab.url);
}) ;
},false);
chrome.tabs
。您必须通知该扩展程序的后台页面才能访问该页面。以下是关于消息传递的一些信息: https://developer.chrome.com/extensions/messaging.html。chrome.tabs.getSelected
to find current URL,chrome.tabs.getSelected
is undefined:{
"content_scripts": [
{
"matches": ["http://*/*" , "https://*/*"],
"js" : [ "main.js" ]
}
],
"manifest_version": 2,
"description": "XX",
"icons": {
"128": "icon.png",
"16": "button.png",
"32": "button.png",
"48": "icon.png"
},
"name": "XX",
"permissions": [ "tabs", "http://*/*", "https://*/*" ],
"version": "1.2"
}
window.addEventListener("keyup", function(e) {
chrome.tabs.getSelected(null, function(tab) { // undefined
alert (tab.url);
});
} , false);
Version 21.0.1180.89 (154005)
window.addEventListener("keyup", function(e) {
chrome.tabs.query( {active:true}, function(tab) {
alert (tab.url);
});
} , false);
chrome.tabs
in a content script. You'll have to message the extension's background page for access to that. Here's some info about messaging: https://developer.chrome.com/extensions/messaging.html.