New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to set arbitrary WebContents as devtools #11300
Conversation
Should we trigger the destruction of I guess this also enabled inspecting devtools window #2835 , LGTM 👍 |
The |
docs/api/web-contents.md
Outdated
@@ -1089,6 +1089,9 @@ with native view, which developers have very limited control of. With the | |||
the devtools in it, including `BrowserWindow`, `BrowserView` and `<webview>` | |||
tag. | |||
|
|||
Note that closing the devtools does not destory the `devToolsWebContents`, it | |||
is caller's responsibility to close `devToolsWebContents`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zcbenz shouldn't this be:
Note that closing the devtools does not destroy the devToolsWebContents
, it
is caller's responsibility to destroy devToolsWebContents
.
6490de4
to
52c6f4b
Compare
When is it available on npm ? |
@LeoMartinDev It will be in next minor/major release, which can take some time since the master branch is not very stable yet. |
@zcbenz @MarshallOfSound
The code above can solve the problem, but the browserContents.debugger.sendCommand does not work. So, I want to ask if there are any good ideas about how to solve this question?( I want the browserView support touch events by using browserContents.debugger.sendCommand api) |
I also encounter the same question, looking for @MarshallOfSound your help. As I know, from chrome 63, the chrome support multiple debugger for one target, So, When we can update to support chrome 63? https://developers.google.com/web/updates/2017/10/devtools-release-notes |
The only work around I can think of, is to execute the command in Devtools WebContents with devtoolsContents.executeJavaScript('...') But you have to figure out which devtools JavaScript API to use. I don't know much about the multiple debugger support of devtools, so I'm not sure if it can solve this problem. |
thanks a lot , i have solve the problem. |
|
Just create a websocket server between chrome devtools and debugger server, then you can send any cmd you want; |
@jacklovepdf |
thanks @jacklovepdf, I have solve the problem with electron3 browserView.addEventListener('dom-ready', () => {
if (isBrowserWebviewReady) return
isBrowserWebviewReady = true
fetch('http://127.0.0.1:8400/json')
.then(res => res.json())
.then(res => {
const target = res.find(child => child.type === 'webview' && child.url === 'about:blank')
if (target) {
devtoolsView.setAttribute('src', `http://127.0.0.1:8400${target.devtoolsFrontendUrl}`)
const ws = new WebSocket(target.webSocketDebuggerUrl)
ws.onopen = () => {
ws.send(JSON.stringify({
id: 1,
method: 'Emulation.setEmitTouchEventsForMouse',
params: {
enabled: true,
configuration: 'mobile'
}
}))
}
devtoolsView.addEventListener('dom-ready', () => {
browserView.setAttribute('src', 'http://xxxx.com')
})
}
})
}) |
Hi, |
thanks @jacklovepdf and @xyytech,I have solve the some problem。 main.js:
renderer.js:
|
Has anyone tried this solution successfully? |
Close #3177.
contents.setDevToolsWebContents(devToolsWebContents)
devToolsWebContents
WebContentsUses the
devToolsWebContents
as the targetWebContents
to show devtools.The
devToolsWebContents
must not have done any navigation, and it should notbe used for other purposes after the call.
By default Electron manages the devtools by creating an internal
WebContents
with native view, which developers have very limited control of. With the
setDevToolsWebContents
method, developers can use anyWebContents
to showthe devtools in it, including
BrowserWindow
,BrowserView
and<webview>
tag.
An example of showing devtools in a
<webview>
tag:An example of showing devtools in a
BrowserWindow
: