Chrome扩展Reactjs chrome.tabs

问题描述 投票:0回答:1

我正在尝试使用React构建chrome扩展,我设法将manifest.json设置为:

{ "short_name": "GitMap", "name": "GitMap", "manifest_version": 2, "browser_action": { "default_popup": "index.html", "default_title": "GitMap" }, "permissions": [ "tabs" ], "version": "1.0" }

。我想在我的React应用程序的app.js文件中使用chrome.tabs.query({ "currentWindow":true}, function(tab) { blahblahblah}访问当前活动选项卡的url,但我收到此错误:TypeError: Cannot read property 'query' of undefined

如何从反应文件中访问“chrome”方法?谢谢

reactjs google-chrome google-chrome-extension
1个回答
0
投票

尝试此解决方案

  1. chrome.tabs.getCurrent(函数(制表符){​​的console.log(tab.url);});
© www.soinside.com 2019 - 2024. All rights reserved.