问题描述
我正在尝试在 window 对象内安装 react-devtools-inline
。我知道,这主要用于 iframe 和嵌入其中的 React 应用程序,但我希望将其安装在主窗口上。
我使用 document.body.appendChild(script)
动态渲染一些 React 组件。我可以事先注册 inline-devtools,但是当我尝试这样做时,我得到 Uncaught TypeError: hook.sub is not a function
这一切都发生在 chrome 扩展 react devtools 被禁用的情况下。
有没有办法在主窗口注册react-devtools-inline
?
谢谢
解决方法
您可以尝试在您的内容中注入一个自调用函数。我将这种方法用于 redux-devtools。
const func = `(${String(this._headFunction)})()`;
const xhrOverrideScript: HTMLScriptElement = document.createElement('script');
xhrOverrideScript.type = 'text/javascript';
xhrOverrideScript.innerHTML = func;
document.head.prepend(xhrOverrideScript);