Add devtools API to inspect shared worker. (#16615)

This commit is contained in:
michtsu 2019-02-01 10:44:24 -08:00 committed by Shelley Vohr
parent efe52f66e4
commit 392458b252
6 changed files with 31 additions and 0 deletions

View file

@ -1416,6 +1416,23 @@ void WebContents::InspectElement(int x, int y) {
managed_web_contents()->InspectElement(x, y); managed_web_contents()->InspectElement(x, y);
} }
void WebContents::InspectSharedWorker() {
if (type_ == REMOTE)
return;
if (!enable_devtools_)
return;
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
if (agent_host->GetType() ==
content::DevToolsAgentHost::kTypeSharedWorker) {
OpenDevTools(nullptr);
managed_web_contents()->AttachTo(agent_host);
break;
}
}
}
void WebContents::InspectServiceWorker() { void WebContents::InspectServiceWorker() {
if (type_ == REMOTE) if (type_ == REMOTE)
return; return;
@ -2178,6 +2195,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("unregisterServiceWorker", .SetMethod("unregisterServiceWorker",
&WebContents::UnregisterServiceWorker) &WebContents::UnregisterServiceWorker)
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
.SetMethod("inspectSharedWorker", &WebContents::InspectSharedWorker)
#if BUILDFLAG(ENABLE_PRINTING) #if BUILDFLAG(ENABLE_PRINTING)
.SetMethod("_print", &WebContents::Print) .SetMethod("_print", &WebContents::Print)
.SetMethod("_getPrinters", &WebContents::GetPrinterList) .SetMethod("_getPrinters", &WebContents::GetPrinterList)

View file

@ -160,6 +160,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params); void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
void DisableDeviceEmulation(); void DisableDeviceEmulation();
void InspectElement(int x, int y); void InspectElement(int x, int y);
void InspectSharedWorker();
void InspectServiceWorker(); void InspectServiceWorker();
v8::Local<v8::Promise> HasServiceWorker(); v8::Local<v8::Promise> HasServiceWorker();
void UnregisterServiceWorker(const base::Callback<void(bool)>&); void UnregisterServiceWorker(const base::Callback<void(bool)>&);

View file

@ -1381,6 +1381,10 @@ Toggles the developer tools.
Starts inspecting element at position (`x`, `y`). Starts inspecting element at position (`x`, `y`).
#### `contents.inspectSharedWorker()`
Opens the developer tools for the shared worker context.
#### `contents.inspectServiceWorker()` #### `contents.inspectServiceWorker()`
Opens the developer tools for the service worker context. Opens the developer tools for the service worker context.

View file

@ -408,6 +408,10 @@ Returns `Boolean` - Whether DevTools window of guest page is focused.
Starts inspecting element at position (`x`, `y`) of guest page. Starts inspecting element at position (`x`, `y`) of guest page.
### `<webview>.inspectSharedWorker()`
Opens the DevTools for the shared worker context present in the guest page.
### `<webview>.inspectServiceWorker()` ### `<webview>.inspectServiceWorker()`
Opens the DevTools for the service worker context present in the guest page. Opens the DevTools for the service worker context present in the guest page.

View file

@ -171,6 +171,9 @@ Object.assign(BrowserWindow.prototype, {
inspectElement (...args) { inspectElement (...args) {
return this.webContents.inspectElement(...args) return this.webContents.inspectElement(...args)
}, },
inspectSharedWorker () {
return this.webContents.inspectSharedWorker()
},
inspectServiceWorker () { inspectServiceWorker () {
return this.webContents.inspectServiceWorker() return this.webContents.inspectServiceWorker()
}, },

View file

@ -44,6 +44,7 @@ exports.syncMethods = new Set([
'findInPage', 'findInPage',
'stopFindInPage', 'stopFindInPage',
'downloadURL', 'downloadURL',
'inspectSharedWorker',
'inspectServiceWorker', 'inspectServiceWorker',
'showDefinitionForSelection', 'showDefinitionForSelection',
'getZoomFactor', 'getZoomFactor',