你如何使用chrome.tabs.getCurrent获取Chrome扩展中的页面对象? [英] How do you use chrome.tabs.getCurrent to get the page object in a Chrome extension?

查看:1292
本文介绍了你如何使用chrome.tabs.getCurrent获取Chrome扩展中的页面对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码旨在将用户正在查看的页面的当前标签对象输出到控制台,但它仅输出未定义的内容。它在浏览器动作页面内运行。

The code is meant to output the current tab object for the page the user is viewing to the console but it just outputs undefined. It's run from within a browser action page.

chrome.tabs.getCurrent( function(tab){
    console.log(tab);
} );

我看了 documentation ,并且据我所知,代码似乎与它所说的相符。

I've looked at the documentation and as far as I can tell the code seems to match what it says.

推荐答案

试试:

Try:

chrome.tabs.getSelected(null, function(tab){
    console.log(tab);
});

这篇关于你如何使用chrome.tabs.getCurrent获取Chrome扩展中的页面对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆