Skip to content
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

feat: emit devtools-open-url event for DevTools link selection #36774

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ The `focus` and `blur` events of `WebContents` should only be used to detect
focus change between different `WebContents` and `BrowserView` in the same
window.

#### Event: 'devtools-open-url'

Returns:

* `url` string - URL of the link that was clicked or selected.

Emitted when a link is clicked in DevTools or 'Open in new tab' is selected for a link in its context menu.

#### Event: 'devtools-opened'

Emitted when DevTools is opened.
Expand Down
8 changes: 8 additions & 0 deletions docs/api/webview-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,14 @@ Returns:

Emitted when mouse moves over a link or the keyboard moves the focus to a link.

### Event: 'devtools-open-url'

Returns:

* `url` string - URL of the link that was clicked or selected.

Emitted when a link is clicked in DevTools or 'Open in new tab' is selected for a link in its context menu.

### Event: 'devtools-opened'

Emitted when DevTools is opened.
Expand Down
1 change: 1 addition & 0 deletions lib/browser/web-view-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const webViewEvents: Record<string, readonly string[]> = {
'dom-ready': [],
'console-message': ['level', 'message', 'line', 'sourceId'],
'context-menu': ['params'],
'devtools-open-url': ['url'],
'devtools-opened': [],
'devtools-closed': [],
'devtools-focused': [],
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3823,6 +3823,10 @@ void WebContents::DevToolsStopIndexing(int request_id) {
devtools_indexing_jobs_.erase(it);
}

void WebContents::DevToolsOpenInNewTab(const std::string& url) {
Emit("devtools-open-url", url);
}

void WebContents::DevToolsSearchInPath(int request_id,
const std::string& file_system_path,
const std::string& query) {
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ class WebContents : public ExclusiveAccessContext,
void DevToolsIndexPath(int request_id,
const std::string& file_system_path,
const std::string& excluded_folders_message) override;
void DevToolsOpenInNewTab(const std::string& url) override;
void DevToolsStopIndexing(int request_id) override;
void DevToolsSearchInPath(int request_id,
const std::string& file_system_path,
Expand Down
5 changes: 4 additions & 1 deletion shell/browser/ui/inspectable_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,10 @@ void InspectableWebContents::SetIsDocked(DispatchCallback callback,
std::move(callback).Run(nullptr);
}

void InspectableWebContents::OpenInNewTab(const std::string& url) {}
void InspectableWebContents::OpenInNewTab(const std::string& url) {
if (delegate_)
delegate_->DevToolsOpenInNewTab(url);
}

void InspectableWebContents::ShowItemInFolder(
const std::string& file_system_path) {
Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/inspectable_web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class InspectableWebContentsDelegate {
virtual void DevToolsIndexPath(int request_id,
const std::string& file_system_path,
const std::string& excluded_folders) {}
virtual void DevToolsOpenInNewTab(const std::string& url) {}
virtual void DevToolsStopIndexing(int request_id) {}
virtual void DevToolsSearchInPath(int request_id,
const std::string& file_system_path,
Expand Down