From 392458b2528fb7ab6592a47bf535419564ba74bc Mon Sep 17 00:00:00 2001 From: michtsu <46971873+michtsu@users.noreply.github.com> Date: Fri, 1 Feb 2019 10:44:24 -0800 Subject: [PATCH] Add devtools API to inspect shared worker. (#16615) --- atom/browser/api/atom_api_web_contents.cc | 18 ++++++++++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + docs/api/web-contents.md | 4 ++++ docs/api/webview-tag.md | 4 ++++ lib/browser/api/browser-window.js | 3 +++ lib/common/web-view-methods.js | 1 + 6 files changed, 31 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index b157d3f8de2f..3752fb02f4ff 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1416,6 +1416,23 @@ void WebContents::InspectElement(int x, int 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() { if (type_ == REMOTE) return; @@ -2178,6 +2195,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("unregisterServiceWorker", &WebContents::UnregisterServiceWorker) .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) + .SetMethod("inspectSharedWorker", &WebContents::InspectSharedWorker) #if BUILDFLAG(ENABLE_PRINTING) .SetMethod("_print", &WebContents::Print) .SetMethod("_getPrinters", &WebContents::GetPrinterList) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e938217c2de3..14c0646323cd 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -160,6 +160,7 @@ class WebContents : public mate::TrackableObject, void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params); void DisableDeviceEmulation(); void InspectElement(int x, int y); + void InspectSharedWorker(); void InspectServiceWorker(); v8::Local HasServiceWorker(); void UnregisterServiceWorker(const base::Callback&); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 22e0b7564f67..5aed4e2899ea 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1381,6 +1381,10 @@ Toggles the developer tools. Starts inspecting element at position (`x`, `y`). +#### `contents.inspectSharedWorker()` + +Opens the developer tools for the shared worker context. + #### `contents.inspectServiceWorker()` Opens the developer tools for the service worker context. diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 406613f87678..0c17200eb236 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -408,6 +408,10 @@ Returns `Boolean` - Whether DevTools window of guest page is focused. Starts inspecting element at position (`x`, `y`) of guest page. +### `.inspectSharedWorker()` + +Opens the DevTools for the shared worker context present in the guest page. + ### `.inspectServiceWorker()` Opens the DevTools for the service worker context present in the guest page. diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 3694acd119c9..d58827ed4602 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -171,6 +171,9 @@ Object.assign(BrowserWindow.prototype, { inspectElement (...args) { return this.webContents.inspectElement(...args) }, + inspectSharedWorker () { + return this.webContents.inspectSharedWorker() + }, inspectServiceWorker () { return this.webContents.inspectServiceWorker() }, diff --git a/lib/common/web-view-methods.js b/lib/common/web-view-methods.js index fd8ba2d7de2a..63f5ce1b6dff 100644 --- a/lib/common/web-view-methods.js +++ b/lib/common/web-view-methods.js @@ -44,6 +44,7 @@ exports.syncMethods = new Set([ 'findInPage', 'stopFindInPage', 'downloadURL', + 'inspectSharedWorker', 'inspectServiceWorker', 'showDefinitionForSelection', 'getZoomFactor',