Skip to content

Commit 0bb2303

Browse files
committed
Add webview.inspectElementAt() for nwjs#6381
1 parent 4dc49de commit 0bb2303

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/browser/nw_chrome_browser_hooks.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ bool CheckStoragePartitionMatches(int render_process_id, const GURL& url) {
139139
return render_process_id == g_cdt_process_id && url.SchemeIs(content_settings::kChromeDevToolsScheme);
140140
}
141141

142+
bool InspectElement(content::WebContents* web_contents, int x, int y) {
143+
scoped_refptr<DevToolsAgentHost> agent_host(DevToolsAgentHost::GetOrCreateFor(web_contents));
144+
DevToolsWindow* window = DevToolsWindow::FindDevToolsWindow(agent_host.get());
145+
if (!window)
146+
return false;
147+
content::RenderFrameHost* rfh = web_contents->GetMainFrame();
148+
DevToolsWindow::InspectElement(rfh, x, y);
149+
return true;
150+
}
151+
142152
void ShowDevtools(bool show, content::WebContents* web_contents, content::WebContents* container) {
143153
content::RenderFrameHost* rfh = web_contents->GetMainFrame();
144154
if (container) {

src/nw_content.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void DocumentFinishHook(blink::WebLocalFrame* frame,
101101
bool PinningRenderer();
102102
void SetPinningRenderer(bool pin);
103103
void ShowDevtools(bool show, content::WebContents* web_contents, content::WebContents* container = nullptr);
104+
bool InspectElement(content::WebContents* web_contents, int x, int y);
104105
bool CheckStoragePartitionMatches(int render_process_id, const GURL& url);
105106
bool RphGuestFilterURLHook(content::RenderProcessHost* rph, const GURL* url);
106107
bool ShouldServiceRequestHook(int child_id, const GURL& url);

test/manual/issue4709-osx-cdthotkey/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
var demodev = document.getElementById('demodev');
2222
document.getElementById('demo').showDevTools(show, demodev);
2323
}
24+
function test_inspect() {
25+
document.getElementById('demo').inspectElementAt(100, 0);
26+
}
2427
</script>
2528
</head>
2629

2730
<body>
2831
<webview partition="persist:trusted" id="demo" src="http://xw.qq.com"></webview>
2932
<webview partition="persist:trusted" id="demodev" src="about:blank"></webview>
3033
<button onclick="test(true)">show</button>
34+
<button onclick="test_inspect()">inspect</button>
3135
</body>
3236

3337
</html>

0 commit comments

Comments
 (0)