Repository navigation
feat: Add runtime devtools API with -runtimedevtools flag - #5378
leaanthony wants to merge 3 commits into
Conversation
This PR adds programmatic devtools access via new `-runtimedevtools` build flag and `application.OpenDevTools()` API. Key features: - New CLI flag: `wails build -runtimedevtools` enables runtime devtools support - Runtime API: `application.OpenDevTools()` for programmatic devtools access - Cross-platform: Works on Windows, Linux, and macOS - Zero overhead: Code excluded by default unless flag is used - Resolves issue #4371 Implementation uses build tags for conditional compilation. Platform-specific implementations for Windows (WebView2 devtools), Linux (WebKit inspector), and macOS (limited to dev/debug builds due to private API restrictions). Usage: ```bash wails build -runtimedevtools # Enable support ``` ```go import "github.com/wailsapp/wails/v3/pkg/application" func openDevtools() { application.OpenDevTools() # Open devtools programmatically } ``` Co-authored-by: multica-agent <github@multica.ai>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughAdds a ChangesRuntime DevTools Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “runtime devtools” capability for v3, wiring a new wails build -runtimedevtools flag to include platform-specific implementations and exposing a public application.OpenDevTools() helper to open devtools programmatically.
Changes:
- Add
-runtimedevtoolsbuild flag that appendsruntimedevtoolstoEXTRA_TAGSduringwails build. - Add
application.OpenDevTools()API to open devtools for the current window. - Introduce platform-specific
runtimedevtoolsimplementations and adjust production/dev build tags to keep default builds devtools-disabled.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| v3/UNRELEASED_CHANGELOG.md | Documents the new build flag + API in the unreleased changelog. |
| v3/pkg/application/devtools.go | Adds application.OpenDevTools() convenience API. |
| v3/pkg/application/webview_window_windows_runtimedevtools.go | Windows implementation for runtime devtools (opt-in via build tag). |
| v3/pkg/application/webview_window_windows_production.go | Excludes Windows production stub when runtimedevtools tag is set. |
| v3/pkg/application/webview_window_linux_runtimedevtools.go | Linux implementation for runtime devtools (opt-in via build tag). |
| v3/pkg/application/webview_window_linux_production.go | Excludes Linux production stub when runtimedevtools tag is set. |
| v3/pkg/application/webview_window_darwin_runtimedevtools.go | macOS implementation for runtime devtools (opt-in via build tag). |
| v3/pkg/application/webview_window_darwin_production.go | Excludes macOS production stub when runtimedevtools tag is set. |
| v3/pkg/application/webview_window_darwin_dev.go | Excludes dev implementation when runtimedevtools tag is set. |
| v3/internal/flags/task_wrapper.go | Adds the -runtimedevtools CLI flag to build flags. |
| v3/internal/commands/task_wrapper.go | Appends runtimedevtools to build tags when the flag is provided. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| func (w *windowsWebviewWindow) enableDevTools(settings *edge.ICoreWebViewSettings) { | ||
| err := settings.PutAreDevToolsEnabled(true) | ||
| if err != nil { | ||
| globalApplication.handleFatalError(err) |
| @@ -0,0 +1,14 @@ | |||
| //go:build windows && runtimedevtools | |||
| @@ -0,0 +1,11 @@ | |||
| //go:build linux && runtimedevtools && !android && !server | |||
| // On platforms where devtools cannot be opened programmatically (e.g., macOS in production), | ||
| // this function will do nothing. | ||
| func OpenDevTools() { | ||
| app := Get() | ||
| if app == nil { |
| //go:build darwin && !ios && !server && (!production || devtools) | ||
| //go:build darwin && !ios && !server && (!production || devtools) && !runtimedevtools | ||
|
|
||
|
|
| func Build(buildFlags *flags.Build, otherArgs []string) error { | ||
| if buildFlags.Tags != "" { | ||
| otherArgs = append(otherArgs, "EXTRA_TAGS="+buildFlags.Tags) | ||
| tags := buildFlags.Tags | ||
| if buildFlags.RuntimeDevtools { | ||
| if tags != "" { | ||
| tags += "," | ||
| } | ||
| tags += "runtimedevtools" | ||
| } | ||
| if tags != "" { | ||
| otherArgs = append(otherArgs, "EXTRA_TAGS="+tags) | ||
| } |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
v3/pkg/application/devtools.go (1)
3-6: 💤 Low valueConsider documenting edge-case behavior.
The function comment states it works only with
-runtimedevtoolsflag and notes macOS production behavior, but doesn't document what happens when:
- No application instance exists (
app == nil)- No current window exists (
currentWindow == nil)- Called before application initialization
These silent early-returns may be intentional, but explicit documentation would improve API clarity.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v3/pkg/application/devtools.go` around lines 3 - 6, Update the OpenDevTools comment to explicitly document its edge-case no-op behavior: state that the function is a no-op (does nothing) when the global app is nil, when there is no currentWindow (currentWindow == nil), when called before application initialization, or when the runtime lacks devtools support (e.g., macOS in production), and retain the note about requiring the -runtimedevtools build flag; reference the OpenDevTools function and the app/currentWindow checks so callers know these conditions cause silent early returns.v3/pkg/application/webview_window_darwin_runtimedevtools.go (1)
31-31: 💤 Low valueInconsistent error messages compared to
webview_window_darwin_dev.go.The error messages differ slightly from the dev variant without clear reason:
- Line 31: "Opening inspector failed" vs. "Opening the inspector failed"
- Line 37: "Opening inspector needs" vs. "Opening the inspector needs"
For consistency and maintainability, align these messages with the dev variant or establish a clear reason for the difference.
Also applies to: 37-37
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v3/pkg/application/webview_window_darwin_runtimedevtools.go` at line 31, Update the two NSLog messages to match the dev variant by changing the literal strings @"Opening inspector failed" and @"Opening inspector needs" to include "the" (i.e., @"Opening the inspector failed" and @"Opening the inspector needs") so the error text is consistent with webview_window_darwin_dev.go; locate the NSLog calls in webview_window_darwin_runtimedevtools.go and replace the quoted message literals accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@v3/pkg/application/webview_window_darwin_runtimedevtools.go`:
- Around line 1-55: The C and Go logic in openDevTools and windowEnableDevTools
is duplicated across webview_window_darwin_runtimedevtools.go and
webview_window_darwin_dev.go; extract the shared C functions (openDevTools,
windowEnableDevTools and any Objective‑C helpers) into a single non-build‑tagged
C/Go file and keep only the small, build‑tagged Go wrappers (methods on
macosWebviewWindow: openDevTools() and enableDevTools()) in the
platform-specific files; ensure the shared file exposes the same C symbols used
by the existing wrapper calls and consolidate error messages/comments there so
both build-tagged files call C.openDevTools and C.windowEnableDevTools without
duplicating implementation.
- Line 25: There is an extra leading space before the tab on the line containing
dispatch_async(dispatch_get_main_queue(), ^{ in
webview_window_darwin_runtimedevtools.go; remove the single space so the line
starts with the tab-aligned indentation (preserve the existing tab and
surrounding code) to fix formatting.
In `@v3/pkg/application/webview_window_windows_runtimedevtools.go`:
- Around line 9-14: The file is missing the import for the edge package used in
the function signature; add the same edge import used in
webview_window_windows_production.go so the type edge.ICoreWebViewSettings
resolves, then run a quick build to ensure windowsWebviewWindow.enableDevTools
compiles (reference the function name enableDevTools and the type
edge.ICoreWebViewSettings to locate where to add the import).
---
Nitpick comments:
In `@v3/pkg/application/devtools.go`:
- Around line 3-6: Update the OpenDevTools comment to explicitly document its
edge-case no-op behavior: state that the function is a no-op (does nothing) when
the global app is nil, when there is no currentWindow (currentWindow == nil),
when called before application initialization, or when the runtime lacks
devtools support (e.g., macOS in production), and retain the note about
requiring the -runtimedevtools build flag; reference the OpenDevTools function
and the app/currentWindow checks so callers know these conditions cause silent
early returns.
In `@v3/pkg/application/webview_window_darwin_runtimedevtools.go`:
- Line 31: Update the two NSLog messages to match the dev variant by changing
the literal strings @"Opening inspector failed" and @"Opening inspector needs"
to include "the" (i.e., @"Opening the inspector failed" and @"Opening the
inspector needs") so the error text is consistent with
webview_window_darwin_dev.go; locate the NSLog calls in
webview_window_darwin_runtimedevtools.go and replace the quoted message literals
accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 746848dd-aa9e-416a-afcc-aabf1bbad09b
📒 Files selected for processing (11)
v3/UNRELEASED_CHANGELOG.mdv3/internal/commands/task_wrapper.gov3/internal/flags/task_wrapper.gov3/pkg/application/devtools.gov3/pkg/application/webview_window_darwin_dev.gov3/pkg/application/webview_window_darwin_production.gov3/pkg/application/webview_window_darwin_runtimedevtools.gov3/pkg/application/webview_window_linux_production.gov3/pkg/application/webview_window_linux_runtimedevtools.gov3/pkg/application/webview_window_windows_production.gov3/pkg/application/webview_window_windows_runtimedevtools.go
| //go:build darwin && runtimedevtools && !ios && !server | ||
|
|
||
| package application | ||
|
|
||
| /* | ||
| #cgo CFLAGS: -mmacosx-version-min=10.13 -x objective-c | ||
| #cgo LDFLAGS: -framework Cocoa | ||
|
|
||
| #import <Cocoa/Cocoa.h> | ||
|
|
||
| #include "webview_window_darwin.h" | ||
|
|
||
| @interface _WKInspector : NSObject | ||
| - (void)show; | ||
| - (void)detach; | ||
| @end | ||
|
|
||
| @interface WKWebView () | ||
| - (_WKInspector *)_inspector; | ||
| @end | ||
|
|
||
| void openDevTools(void *window) { | ||
| #if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 | ||
| if (@available(macOS 12.0, *)) { | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| WebviewWindow* nsWindow = (WebviewWindow*)window; | ||
|
|
||
| @try { | ||
| [nsWindow.webView._inspector show]; | ||
| } @catch (NSException *exception) { | ||
| NSLog(@"Opening inspector failed: %@", exception.reason); | ||
| return; | ||
| } | ||
| }); | ||
| } | ||
| #else | ||
| NSLog(@"Opening inspector needs at least MacOS 12"); | ||
| #endif | ||
| } | ||
|
|
||
| void windowEnableDevTools(void* nsWindow) { | ||
| WebviewWindow* window = (WebviewWindow*)nsWindow; | ||
| [window.webView.configuration.preferences setValue:@YES forKey:@"developerExtrasEnabled"]; | ||
| } | ||
|
|
||
| */ | ||
| import "C" | ||
|
|
||
| func (w *macosWebviewWindow) openDevTools() { | ||
| C.openDevTools(w.nsWindow) | ||
| } | ||
|
|
||
| func (w *macosWebviewWindow) enableDevTools() { | ||
| C.windowEnableDevTools(w.nsWindow) | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift
Significant code duplication with webview_window_darwin_dev.go.
This file duplicates approximately 50 lines of C and Go code from webview_window_darwin_dev.go. The implementations are nearly identical except for:
- Minor wording differences in error messages (lines 31, 37)
- Missing comment on line 41
This creates a maintenance burden where bug fixes and enhancements must be applied to both files. Consider extracting the common C implementation into a shared file (without build tags, as noted in learnings) and having both build-tagged files import/reference it.
Based on learnings: shared functions can be defined without build tags but invoked from platform-specific files with build constraints. This pattern would eliminate duplication while maintaining build-tag isolation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@v3/pkg/application/webview_window_darwin_runtimedevtools.go` around lines 1 -
55, The C and Go logic in openDevTools and windowEnableDevTools is duplicated
across webview_window_darwin_runtimedevtools.go and
webview_window_darwin_dev.go; extract the shared C functions (openDevTools,
windowEnableDevTools and any Objective‑C helpers) into a single non-build‑tagged
C/Go file and keep only the small, build‑tagged Go wrappers (methods on
macosWebviewWindow: openDevTools() and enableDevTools()) in the
platform-specific files; ensure the shared file exposes the same C symbols used
by the existing wrapper calls and consolidate error messages/comments there so
both build-tagged files call C.openDevTools and C.windowEnableDevTools without
duplicating implementation.
- Add missing edge package import to Windows runtimedevtools file - Fix build tag overlap by adding production constraint to runtimedevtools files - Update OpenDevTools documentation to clarify edge-case behavior - Remove extra blank line after go:build in darwin_dev.go - Add unit tests for RuntimeDevtools CLI flag handling - Fix formatting (extra space before tab) in darwin_runtimedevtools.go - Align error messages with darwin_dev.go for consistency Resolves issues: - Missing import causing compilation failure - Build tag overlap causing duplicate method definitions - Incomplete documentation about no-op conditions - Formatting inconsistencies - Missing test coverage for new CLI flag See: #5378 Co-authored-by: multica-agent <github@multica.ai>
Summary
Adds programmatic devtools access via new `-runtimedevtools` build flag and `application.OpenDevTools()` API.
Resolves
Recreates #4371 for v3
Key Features
Usage
```bash
wails build -runtimedevtools # Enable support
```
```go
import "github.com/wailsapp/wails/v3/pkg/application"
func openDevtools() {
application.OpenDevTools() # Open devtools programmatically
}
```
Implementation
Uses build tags for conditional compilation - runtime devtools code is only included when explicitly enabled via the `-runtimedevtools` flag.
Platform-specific implementations:
The `openDevTools()` function calls the implementation on the current window, allowing programmatic access from Go backend code.
Generated with Claude Code
Summary by CodeRabbit
-runtimedevtoolsbuild flag to enable runtime developer tools.OpenDevTools()API to programmatically open the app's developer tools (available when built with the runtimedevtools flag; platform availability may vary).