How to open developer tools inside of a webview

我与影子孤独终老i 提交于 2020-04-18 05:35:11

问题


I'm developing a browser using Electron. I've been trying to open the developer tools of a webview, and I did it using that code:

document.getElementById("MyWebView").openDevTools();

But the problem is that the developer tools' window is opened as a pop-up window (another window):

I want to know who can I open it side by side to the webview (by creating another webview that shows the developer tools or by some other ways...). For example, here's a photo of Baker Browser (Braker Browser is a browser that is developed using Electron):

Here's some info about the current version of Electron that I'm using:

Electron version: 8.2.0
Chromium version: 80.0.3987.158
NodeJS version: 12.13.0

If there's some missing info that you need to have in order to help me, please ask for it. Thank you for helping in advance!

*Edit:**


回答1:


Click the hamburger menu icon at the top right of devtools. The "Dock side" item at the top of that menu should allow you to choose where you want the tools.

But under some circumstances Chromium doesn't have enough control over the browser window to place the devtools in it. You may be hitting that problem with your embedded Electron view.




回答2:


It actually turned out to be easy:

const wv = document.getElementById("MyWebView");
wv.addEventListener('dom-ready', () => {
  const devtoolsView = document.getElementById('DevTools');
  const browser = wv.getWebContents();
  browser.setDevToolsWebContents(devtoolsView.getWebContents());
  browser.openDevTools();
});


来源:https://stackoverflow.com/questions/60989426/how-to-open-developer-tools-inside-of-a-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!