【问题标题】:Open devtools of a webview inside another webview in electron?在电子的另一个webview中打开一个webview的devtools?
【发布时间】:2018-11-18 11:11:15
【问题描述】:

我用电子开发了一个工具。应用中有两个 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 的 DevTools,browserContents.debugger.sendCommand 将无法工作。我知道使用 chrome-devtools 方案打开 webview 的 devtools 的方法可以解决这个问题,但我不知道开发工具如何连接到页面 webview。
  • 你可能会在这里找到你一直在等待的答案:stackoverflow.com/a/60990622/13057660

标签: webview electron devtools


【解决方案1】:
<webview-1>.addEventListener('dom-ready', () => {
    require("electron").remote.webContents.fromId(<webview-1>.getWebContentsId()).setDevToolsWebContents(remote.webContents.fromId(<webview-2>.getWebContentsId()));
});
 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多