webview - 在 Electron 中的另一个Web View 中打开Web View 的devtools?

标签 webview electron devtools

我用 Electron 开发工具。该应用程序中有两个Webview组件。一个显示html页面,另一个显示用于调试页面的chrome devtools。当前的解决方案是:

const browserContents = browserView.getWebContents()
const devtoolsContents = devtoolsView.getWebContents()

browserContents.setDevToolsWebContents(devtoolsContents)
browserContents.debugger.attach();

browserContents.openDevTools({
     detach: true
})

browserContents.debugger.sendCommand(    // not work
          'Emulation.setTouchEmulationEnabled', 
  {
    enabled: true,
    configuration: 'mobile',
  }, function(err){
     if(err){console.log("Emulation err:", err);}
  }
);

上面的代码可以解决问题,但是setTouchEmulationEnabled不起作用。所以,我想问一下关于如何解决这个问题是否有好的想法?

最佳答案

<webview-1>.addEventListener('dom-ready', () => {
    require("electron").remote.webContents.fromId(<webview-1>.getWebContentsId()).setDevToolsWebContents(remote.webContents.fromId(<webview-2>.getWebContentsId()));
});
 

关于webview - 在 Electron 中的另一个Web View 中打开Web View 的devtools?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50759817/

相关文章:

Android webview 显示 url 源而不是正常加载 url

Android:从我网站的收据页面检索付款信息

javascript - stringByEvaluatingJavaScript 对象没有 ID

node.js - 运行 npm 脚本命令时覆盖 package.json 键

node.js - 在 Angular 2 应用程序中导入 Node js 模块

cocoa - 从 Mail.app 和 Notes.app 显示 WebArchive

javascript - Electron 无法获取当前文件路径

Travis-ci 中的 R 包检查包依赖性错误

r - 使用 check() 测试失败

javascript - 我怎样才能知道网站正在运行什么版本的 ember?