如何在 Chrome 扩展中访问私有 API

How do I access Private APIs in Chrome extension

我需要获取 mac addressusername 以及 computer 的值。我想用 networkingPrivate 来做到这一点。但是我无法访问它。

我在 manifest.json 文件中这样写:

"permissions": ["networkingPrivate"]

通常你不能,因为它们是私有的,正是为了私有,而不是 public API。也是whitelisted to specific extensions by Google or its trusted associates

对于您自己的个人使用,您可能会通过 运行 Chrome 使用自定义命令行参数 --whitelisted-extension-id=abcd 获得成功,其中 abcd 代表您的扩展程序的 32 个字符的 ID,如图所示在 chrome://extensions 页面上,当在页面右上角启用开发者模式开关时。或者您可以通过找到其 manifest.json 并将其 "key" 复制到您自己的 manifest.json.

来模仿受信任扩展的 ID

对于 public 扩展,您必须使用变通方法。例如,编写一个单独的实用程序并通过 nativeMessaging API.

调用它