如何在 Electron 中安装 MetaMask 扩展?
How can I install the MetaMask extension in Electron?
我已经成功安装了 https://github.com/aragon/metamask-plugin
的扩展
启动 Electron 应用程序时,我可以看到 MetaMask 插件已加载,但无法对其执行太多操作。有一些错误:
Uncaught TypeError: global._runtime.onConnect is not a function
at Object.connect (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139)
at setupStreams (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216)
at Object.<anonymous> (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187)
at Object.3../lib/extension (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265)
at s (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at e (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
connect @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139
setupStreams @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187
3../lib/extension @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265
s @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
e @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
和
App.js:49 Uncaught TypeError: window._setupMetaMaskPageStream is not a function
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:1081:14)
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:19790:30)
at Object.ReactErrorUtils.invokeGuardedCallback (webpack:///./node_modules/react-dom/lib/ReactErrorUtils.js?:69:16)
at executeDispatch (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:85:21)
at Object.executeDispatchesInOrder (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:108:5)
at executeDispatchesAndRelease (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:43:22)
at executeDispatchesAndReleaseTopLevel (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:54:10)
at Array.forEach (native)
at forEachAccumulated (webpack:///./node_modules/react-dom/lib/forEachAccumulated.js?:24:9)
at Object.processEventQueue (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:254:7)
这两个错误都是函数作用域绑定错误。函数 this.setupMetaMaskPageStream
和 this._runtime.onConnect
是从 MetaMaskController 中的其他函数调用的,但它们似乎在不保留 MetaMask 控制器范围的情况下被调用,默认为全局上下文(因此 window._setupMetaMaskPageStream
).
没有看到你的代码,很难知道你是如何在错误的上下文中调用这些方法的,但它可能涉及 bind
或 call
函数。
我已经成功安装了 https://github.com/aragon/metamask-plugin
的扩展启动 Electron 应用程序时,我可以看到 MetaMask 插件已加载,但无法对其执行太多操作。有一些错误:
Uncaught TypeError: global._runtime.onConnect is not a function
at Object.connect (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139)
at setupStreams (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216)
at Object.<anonymous> (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187)
at Object.3../lib/extension (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265)
at s (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at e (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
connect @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139
setupStreams @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187
3../lib/extension @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265
s @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
e @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
和
App.js:49 Uncaught TypeError: window._setupMetaMaskPageStream is not a function
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:1081:14)
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:19790:30)
at Object.ReactErrorUtils.invokeGuardedCallback (webpack:///./node_modules/react-dom/lib/ReactErrorUtils.js?:69:16)
at executeDispatch (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:85:21)
at Object.executeDispatchesInOrder (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:108:5)
at executeDispatchesAndRelease (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:43:22)
at executeDispatchesAndReleaseTopLevel (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:54:10)
at Array.forEach (native)
at forEachAccumulated (webpack:///./node_modules/react-dom/lib/forEachAccumulated.js?:24:9)
at Object.processEventQueue (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:254:7)
这两个错误都是函数作用域绑定错误。函数 this.setupMetaMaskPageStream
和 this._runtime.onConnect
是从 MetaMaskController 中的其他函数调用的,但它们似乎在不保留 MetaMask 控制器范围的情况下被调用,默认为全局上下文(因此 window._setupMetaMaskPageStream
).
没有看到你的代码,很难知道你是如何在错误的上下文中调用这些方法的,但它可能涉及 bind
或 call
函数。