Skip to content

feat: Add runtime devtools API with -runtimedevtools flag - #5378

Closed
leaanthony wants to merge 3 commits into
masterfrom
agent/multica-maintainer/61994765
Closed

leaanthony wants to merge 3 commits into
masterfrom
agent/multica-maintainer/61994765

Conversation

@leaanthony

@leaanthony leaanthony commented May 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds programmatic devtools access via new `-runtimedevtools` build flag and `application.OpenDevTools()` API.

Resolves

Recreates #4371 for v3

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

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:

  • Windows: WebView2 devtools via `OpenDevToolsWindow()`
  • Linux: WebKit inspector
  • macOS: Limited to dev/debug builds due to private API restrictions (inspector API requires macOS 12+)

The `openDevTools()` function calls the implementation on the current window, allowing programmatic access from Go backend code.

Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a -runtimedevtools build flag to enable runtime developer tools.
    • Added an OpenDevTools() API to programmatically open the app's developer tools (available when built with the runtimedevtools flag; platform availability may vary).

Review Change Stack

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>
Copilot AI review requested due to automatic review settings May 9, 2026 09:45
@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 43def51a-ea3a-40a7-9dd4-8179065770d3

📥 Commits

Reviewing files that changed from the base of the PR and between 3f5730c and c495ca0.

📒 Files selected for processing (6)
  • v3/internal/commands/task_wrapper_test.go
  • v3/pkg/application/devtools.go
  • v3/pkg/application/webview_window_darwin_dev.go
  • v3/pkg/application/webview_window_darwin_runtimedevtools.go
  • v3/pkg/application/webview_window_linux_runtimedevtools.go
  • v3/pkg/application/webview_window_windows_runtimedevtools.go
✅ Files skipped from review due to trivial changes (1)
  • v3/pkg/application/webview_window_linux_runtimedevtools.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • v3/pkg/application/webview_window_windows_runtimedevtools.go
  • v3/pkg/application/webview_window_darwin_dev.go
  • v3/pkg/application/webview_window_darwin_runtimedevtools.go

Walkthrough

Adds a -runtimedevtools build flag, integrates it into build tag propagation, exposes application.OpenDevTools() as a public API, and provides platform-specific runtime DevTools implementations for macOS, Linux, and Windows using build-tag conditional compilation; production/dev files are excluded when the flag is enabled.

Changes

Runtime DevTools Feature

Layer / File(s) Summary
Flag definition
v3/internal/flags/task_wrapper.go
Adds RuntimeDevtools boolean field to Build flags and updates Tags description.
Build system integration
v3/internal/commands/task_wrapper.go, v3/internal/commands/task_wrapper_test.go
Appends runtimedevtools into constructed build tags and forwards it via EXTRA_TAGS; adds tests for RuntimeDevtools and combined Tags+RuntimeDevtools.
Public API and docs
v3/pkg/application/devtools.go, v3/UNRELEASED_CHANGELOG.md
Introduces exported OpenDevTools() and documents the new -runtimedevtools flag in the changelog.
Build constraints (production/dev)
v3/pkg/application/webview_window_darwin_dev.go, v3/pkg/application/webview_window_darwin_production.go, v3/pkg/application/webview_window_linux_production.go, v3/pkg/application/webview_window_windows_production.go
Updates Go build tags to exclude these variants when runtimedevtools is enabled.
macOS runtime implementation
v3/pkg/application/webview_window_darwin_runtimedevtools.go
Adds cgo/Objective-C helpers and Go wrappers to open and enable WKWebView DevTools on macOS (macOS 12+ gating, main-queue dispatch, Objective-C exception handling).
Linux runtime implementation
v3/pkg/application/webview_window_linux_runtimedevtools.go
Adds openDevTools() and enableDevTools() that delegate to package-level functions using the window's webview.
Windows runtime implementation
v3/pkg/application/webview_window_windows_runtimedevtools.go
Adds Windows production runtimedevtools file integrating with Chromium WebView to open DevTools and enable DevTools settings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • wailsapp/wails#4968: Both PRs modify build tag propagation via EXTRA_TAGS and update v3/internal/commands/task_wrapper.go and v3/internal/flags/task_wrapper.go.

Suggested labels

Enhancement, go, Windows, MacOS, Linux, v3-alpha, size:L, lgtm

Poem

🐰 A small flag leaps into sight,
runtimedevtools brings debugging light,
A call to OpenDevTools, quick and neat,
Mac, Linux, Windows — all can peek,
Hop on, inspect — the rabbit says, "Delight!"

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete relative to the template requirements; it lacks an explicit issue reference (Fixes #), type of change checkbox selection, testing details, platform testing checkboxes, and test configuration output. Add 'Fixes #4371' at the top, select 'New feature' checkbox, document testing performed on each platform, and include relevant test configuration details or wails doctor output.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature: adding a runtime devtools API with the new -runtimedevtools flag, which matches the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/multica-maintainer/61994765
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch agent/multica-maintainer/61994765

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -runtimedevtools build flag that appends runtimedevtools to EXTRA_TAGS during wails build.
  • Add application.OpenDevTools() API to open devtools for the current window.
  • Introduce platform-specific runtimedevtools implementations 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.

Comment on lines +7 to +12
}

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
Comment thread v3/pkg/application/devtools.go Outdated
Comment on lines +5 to +9
// 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


Comment on lines 21 to 31
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)
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
v3/pkg/application/devtools.go (1)

3-6: 💤 Low value

Consider documenting edge-case behavior.

The function comment states it works only with -runtimedevtools flag 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 value

Inconsistent 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

📥 Commits

Reviewing files that changed from the base of the PR and between 10845c1 and 3f5730c.

📒 Files selected for processing (11)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/internal/commands/task_wrapper.go
  • v3/internal/flags/task_wrapper.go
  • v3/pkg/application/devtools.go
  • v3/pkg/application/webview_window_darwin_dev.go
  • v3/pkg/application/webview_window_darwin_production.go
  • v3/pkg/application/webview_window_darwin_runtimedevtools.go
  • v3/pkg/application/webview_window_linux_production.go
  • v3/pkg/application/webview_window_linux_runtimedevtools.go
  • v3/pkg/application/webview_window_windows_production.go
  • v3/pkg/application/webview_window_windows_runtimedevtools.go

Comment on lines +1 to +55
//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)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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>
@leaanthony leaanthony added this to the v3.0.0-beta.2 milestone May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants