简体   繁体   English

chrome.contextMenus.create 的 onclick 回调中的 `info` 类型是什么?

[英]what's the type for `info` in the onclick callback in chrome.contextMenus.create?

I'm using TypeScript to build a chrome extension, and in my background.js file (which as the name may imply is one of my background scripts) I am creating a new contextMenu , using the chrome.contextMenus.create .我正在使用 TypeScript 构建一个 chrome 扩展程序,并在我的 background.js 文件(顾名思义是我的后台脚本之一)中,我正在使用chrome.contextMenus.create创建一个新的contextMenu This method takes an optional onClick paramter in input where one of the arguments is info (docs can be found here ).此方法在输入中采用可选的 onClick 参数,其中 arguments 之一是info (可以在此处找到文档)。 Is anyone able to tell me where I can find more information on the type / structure of this info arg?有谁能告诉我在哪里可以找到有关此info参数的类型/结构的更多信息? I'm fairly sure it depends on the contextType for the context menu but can't seem to find anything usefule here.我相当确定它取决于上下文菜单的contextType但似乎无法在这里找到任何有用的东西。

Always great when you find the answer a few minutes after posting the question...当您在发布问题几分钟后找到答案时,总是很棒...

For reference, for event pages, adding the onClick parameter in the create method isn't supported, and instead you have to add a listener like作为参考,对于事件页面,不支持在创建方法中添加onClick参数,而是必须添加一个监听器,如

chrome.contextMenus.onClick.addListener(function(info, tab) {
    ...
})

In this case, the info argument has the type chrome.contextMenus.OnClickData .在这种情况下, info参数的类型为chrome.contextMenus.OnClickData

As an FYI, you can add the type definitions for the chrome API if you're using npm with仅供参考,如果您使用npm ,则可以为 chrome API 添加类型定义

npm install --save-dev @types/chrome

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM