Merge pull request #3974 from leethomas/fix-devtools-api
Fix devtools api
This commit is contained in:
commit
4cdee5547f
8 changed files with 78 additions and 0 deletions
|
@ -780,6 +780,13 @@ bool WebContents::IsDevToolsOpened() {
|
|||
return managed_web_contents()->IsDevToolsViewShowing();
|
||||
}
|
||||
|
||||
bool WebContents::IsDevToolsFocused() {
|
||||
if (type_ == REMOTE)
|
||||
return false;
|
||||
|
||||
return managed_web_contents()->GetView()->IsDevToolsViewFocused();
|
||||
}
|
||||
|
||||
void WebContents::EnableDeviceEmulation(
|
||||
const blink::WebDeviceEmulationParams& params) {
|
||||
if (type_ == REMOTE)
|
||||
|
@ -1080,6 +1087,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
||||
.SetMethod("isDevToolsFocused", &WebContents::IsDevToolsFocused)
|
||||
.SetMethod("enableDeviceEmulation",
|
||||
&WebContents::EnableDeviceEmulation)
|
||||
.SetMethod("disableDeviceEmulation",
|
||||
|
|
|
@ -79,6 +79,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void OpenDevTools(mate::Arguments* args);
|
||||
void CloseDevTools();
|
||||
bool IsDevToolsOpened();
|
||||
bool IsDevToolsFocused();
|
||||
void ToggleDevTools();
|
||||
void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
|
||||
void DisableDeviceEmulation();
|
||||
|
|
|
@ -83,6 +83,7 @@ BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
|||
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
||||
BrowserWindow::closeDevTools = -> @webContents.closeDevTools()
|
||||
BrowserWindow::isDevToolsOpened = -> @webContents.isDevToolsOpened()
|
||||
BrowserWindow::isDevToolsFocused = -> @webContents.isDevToolsFocused()
|
||||
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
|
||||
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
|
||||
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
|
||||
|
|
|
@ -13,6 +13,9 @@ supportedWebViewEvents = [
|
|||
'did-get-redirect-request'
|
||||
'dom-ready'
|
||||
'console-message'
|
||||
'devtools-opened'
|
||||
'devtools-closed'
|
||||
'devtools-focused'
|
||||
'new-window'
|
||||
'close'
|
||||
'crashed'
|
||||
|
|
|
@ -15,6 +15,9 @@ WEB_VIEW_EVENTS =
|
|||
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame']
|
||||
'dom-ready': []
|
||||
'console-message': ['level', 'message', 'line', 'sourceId']
|
||||
'devtools-opened': []
|
||||
'devtools-closed': []
|
||||
'devtools-focused': []
|
||||
'new-window': ['url', 'frameName', 'disposition', 'options']
|
||||
'close': []
|
||||
'crashed': []
|
||||
|
|
|
@ -650,3 +650,15 @@ Emitted when a page's theme color changes. This is usually due to encountering a
|
|||
```html
|
||||
<meta name='theme-color' content='#ff0000'>
|
||||
```
|
||||
|
||||
### Event: 'devtools-opened'
|
||||
|
||||
Emitted when DevTools is opened.
|
||||
|
||||
### Event: 'devtools-closed'
|
||||
|
||||
Emitted when DevTools is closed.
|
||||
|
||||
### Event: 'devtools-focused'
|
||||
|
||||
Emitted when DevTools is focused / opened.
|
||||
|
|
4
spec/fixtures/pages/base-page.html
vendored
Normal file
4
spec/fixtures/pages/base-page.html
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
|
@ -279,6 +279,52 @@ describe '<webview> tag', ->
|
|||
webview.src = "file://#{fixtures}/pages/close.html"
|
||||
document.body.appendChild webview
|
||||
|
||||
describe 'devtools-opened event', ->
|
||||
it 'should fire when webview.openDevTools() is called', (done) ->
|
||||
listener = ->
|
||||
webview.removeEventListener 'devtools-opened', listener
|
||||
webview.closeDevTools()
|
||||
done()
|
||||
|
||||
webview.addEventListener 'devtools-opened', listener
|
||||
webview.addEventListener 'dom-ready', ->
|
||||
webview.openDevTools()
|
||||
|
||||
webview.src = "file://#{fixtures}/pages/base-page.html"
|
||||
document.body.appendChild webview
|
||||
|
||||
describe 'devtools-closed event', ->
|
||||
it 'should fire when webview.closeDevTools() is called', (done) ->
|
||||
listener2 = ->
|
||||
webview.removeEventListener 'devtools-closed', listener2
|
||||
done()
|
||||
|
||||
listener = ->
|
||||
webview.removeEventListener 'devtools-opened', listener
|
||||
webview.closeDevTools()
|
||||
|
||||
webview.addEventListener 'devtools-opened', listener
|
||||
webview.addEventListener 'devtools-closed', listener2
|
||||
webview.addEventListener 'dom-ready', ->
|
||||
webview.openDevTools()
|
||||
|
||||
webview.src = "file://#{fixtures}/pages/base-page.html"
|
||||
document.body.appendChild webview
|
||||
|
||||
describe 'devtools-focused event', ->
|
||||
it 'should fire when webview.openDevTools() is called', (done) ->
|
||||
listener = ->
|
||||
webview.removeEventListener 'devtools-focused', listener
|
||||
webview.closeDevTools()
|
||||
done()
|
||||
|
||||
webview.addEventListener 'devtools-focused', listener
|
||||
webview.addEventListener 'dom-ready', ->
|
||||
webview.openDevTools()
|
||||
|
||||
webview.src = "file://#{fixtures}/pages/base-page.html"
|
||||
document.body.appendChild webview
|
||||
|
||||
describe '<webview>.reload()', ->
|
||||
it 'should emit beforeunload handler', (done) ->
|
||||
listener = (e) ->
|
||||
|
|
Loading…
Reference in a new issue