【问题标题】:Chrome Extension Reactjs chrome.tabsChrome 扩展 Reactjs chrome.tabs
【发布时间】:2017-12-24 18:53:20
【问题描述】:

我正在尝试使用 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" }

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

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

【问题讨论】:

  • 该错误表示该库未加载,因此它不熟悉您正在调用的方法。尝试查看react-chrome-extension-boilerplate,了解如何使用带有 chrome 扩展的 reacjts。

标签: reactjs google-chrome google-chrome-extension


【解决方案1】:

试试这个解决方案

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 2022-10-06
    • 2015-01-17
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多