reactjs - Electron - Webview 必须附加到 DOM 错误
问题描述
在我的 Electron/React 应用程序中,我可以打开托管在另一个 Web 应用程序上的视频内容。我所做的是webview
使用 URL 呈现所需页面。这是我的例子:
const App = ({ computedMatch }) => {
const { audioMuted } = useSelector(({ window }) => window);
const titleId = computedMatch.params.id;
const src = `${BASE_URL}/${titleId}`;
useEffect(() => {
const webview = document.querySelector('webview');
if (webview) {
webview.setAudioMuted(audioMuted);
}
}, [audioMuted]);
return <webview src={src} />;
};
在 Windows 栏上,我有一个静音按钮图标,按下静音按钮,将 Redux 状态更新audioMuted
为true
。当状态发生变化时,useEffect
就会发生作用
一方面,这个解决方案似乎有效,但经过一些测试,有时我会收到这个错误:
error: uncaughtException: The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.
Error: The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.
如何修复此错误以使其永远不会出现?
解决方案
推荐阅读
- excel - 向下填充公式到最后一个可见单元格
- python - 如何计算字符串的出现次数以熊猫数据框中逗号分隔值中的特定子字符串开头?
- google-sheets - Countifs N 跨多个标准计数(在数据验证中),但如果数据验证单元格为空白,则不返回零
- css - rgb() 和 rgba() 不透明度有什么区别?
- angular - 在模板中调用 Angular 方法比 {{ }} 更有效吗?
- ruby-on-rails - Webpacker::Manifest::MissingEntryError 当 stylesheet_packs_with_chunks_tag
- twilio - Twilio 消息服务 - 将传入的 SMS 路由到工作室流程不起作用
- python - 计数表达式
- c# - 在 Windows 服务中立即运行计时器
- java - Java 扫描器实用程序仅在我的简单程序中工作一次