Skip to content

fix(v3/windows): Fix ensure JS string is executed when webview is created#4876

Closed
popaprozac wants to merge 7 commits intowailsapp:v3-alphafrom
popaprozac:fix/windows-exec-js
Closed

fix(v3/windows): Fix ensure JS string is executed when webview is created#4876
popaprozac wants to merge 7 commits intowailsapp:v3-alphafrom
popaprozac:fix/windows-exec-js

Conversation

@popaprozac
Copy link
Copy Markdown
Contributor

@popaprozac popaprozac commented Jan 12, 2026

Description

Currently the JS and CSS strings passed in application.WebviewWindowOptions when creating a new webview on Windows are only executed if an HTML string is also passed.

This first draft runs them independently after the initial navigation completes. After review may refactor to use the original chromium.Init() call.

Fixes # (issue)

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

 Wails (v3.0.0-dev)  Wails Doctor

# System

┌─────────────────────────────────────────────────────────────────────────────────────────────┐
| Name              | Windows 10 Pro                                                          |
| Version           | 2009 (Build: 26100)                                                     |
| ID                | 24H2                                                                    |
| Branding          | Windows 11 Pro                                                          |
| Platform          | windows                                                                 |
| Architecture      | amd64                                                                   |
| Go WebView2Loader | true                                                                    |
| WebView2 Version  | 143.0.3650.139                                                          |
| CPU               | virt-9.1                                                                |
| GPU 1             | Red Hat VirtIO GPU DOD controller (Red Hat, Inc.) - Driver: 22.7.38.43  |
| Memory            | 8GB                                                                     |
└─────────────────────────────────────────────────────────────────────────────────────────────┘

# Build Environment

┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-dev                               |
| Go Version   | go1.25.5                                 |
| Revision     | 9db2f74c443016aa31c2c25ff326f7e28a81dbc7 |
| Modified     | true                                     |
| -buildmode   | exe                                      |
| -compiler    | gc                                       |
| CGO_ENABLED  | 0                                        |
| GOAMD64      | v1                                       |
| GOARCH       | amd64                                    |
| GOOS         | windows                                  |
| vcs          | git                                      |
| vcs.modified | true                                     |
| vcs.revision | 9db2f74c443016aa31c2c25ff326f7e28a81dbc7 |
| vcs.time     | 2026-01-11T02:54:04Z                     |
└─────────────────────────────────────────────────────────┘

# Dependencies

┌────────────────────────────────────────────────────────────────────────────────┐
| NSIS                       | Not Installed                                     |
| MakeAppx.exe (Windows SDK) | Not Installed                                     |
| MSIX Packaging Tool        | Not Installed                                     |
| SignTool.exe (Windows SDK) | Not Installed                                     |
| npm                        | 10.9.2                                            |
| docker                     | *Not installed (optional - for cross-compilation) |
|                                                                                |
└─────────────────────────── * - Optional Dependency ────────────────────────────┘

# Checking for issues

 SUCCESS  No issues found

# Diagnosis

 SUCCESS  Your system is ready for Wails development!

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Restores execution of custom JavaScript on first navigation for Windows webviews so user scripts run reliably.
    • Ensures user-provided CSS is applied during the initial webview load on Windows.
    • Fixes a missing initialization step so per-window scripts and styles initialize correctly on first load.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 12, 2026

Walkthrough

Gates execution of user-provided JS and CSS to the first Windows WebView navigation by removing their one-time setup in setupChromium and moving injection/execution into navigationCompleted; adds a changelog entry noting the bug fix.

Changes

Cohort / File(s) Summary
Changelog
v3/UNRELEASED_CHANGELOG.md
Added a Fixed entry: "Fix missing execJS call when creating Windows webview."
Windows WebView implementation
v3/pkg/application/webview_window_windows.go
Removed aggregation/initialization of options.JS/options.CSS in setupChromium; added guarded execution of options.JS and CSS injection (via w.execJS) inside navigationCompleted, limited to the first navigation (!w.webviewNavigationCompleted).

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Bug, Windows, v3, v3-alpha, size:M, Documentation

Poem

🐰 I hopped through code with careful paws,
I moved the scripts to when the page first draws.
One flag now stops a double call,
First load runs scripts — that’s the call.
🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing JS execution on Windows webview creation, which aligns with the core bugfix in the changeset.
Description check ✅ Passed The description covers the core issue, type of change, testing details, and most checklist items, though it lacks a specific issue number reference and some testing details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @v3/pkg/application/webview_window_windows.go:
- Around line 2119-2128: The code references an undefined variable cssEscaped
when embedding w.parent.options.CSS into a JS string inside the webview
navigation block; define cssEscaped by taking w.parent.options.CSS and escaping
single quotes, backslashes and newlines (e.g., replace \ with \\, ' with \', and
normalize newlines to \n) before using fmt.Sprintf, so update the block in
webview_window_windows.go where execJS is called (look for
webviewNavigationCompleted and execJS) to compute cssEscaped from
w.parent.options.CSS and use that escaped value in the generated JS string.
🧹 Nitpick comments (1)
v3/UNRELEASED_CHANGELOG.md (1)

26-26: Minor grammar issue in changelog entry.

The phrasing "Fix adds missing" is awkward. Consider rewording to follow the pattern used in the example entries.

📝 Suggested fix
-- Fix adds missing execJS call when creating Windows webview
+- Fix missing execJS call when creating Windows webview
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9db2f74 and a679c0d.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/webview_window_windows.go
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-13T19:52:13.812Z
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4783
File: v3/pkg/events/events.go:72-100
Timestamp: 2025-12-13T19:52:13.812Z
Learning: In Wails v3, the linux:WindowLoadChanged event was intentionally removed as a breaking change and replaced with four granular WebKit2 load events: linux:WindowLoadStarted, linux:WindowLoadRedirected, linux:WindowLoadCommitted, and linux:WindowLoadFinished. Users should migrate to linux:WindowLoadFinished for detecting when the WebView has finished loading.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-12-29T08:02:15.134Z
Learnt from: popaprozac
Repo: wailsapp/wails PR: 4839
File: docs/src/content/docs/reference/window.mdx:616-620
Timestamp: 2025-12-29T08:02:15.134Z
Learning: In Wails v3, the correct API for creating windows is `app.Window.New()` and `app.Window.NewWithOptions(...)`, not `app.NewWebviewWindow()` or `app.NewWebviewWindowWithOptions(...)`. The Application struct exposes a Window field of type *WindowManager that provides these methods.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2026-01-04T08:01:00.038Z
Learnt from: symball
Repo: wailsapp/wails PR: 4853
File: v2/internal/system/system.go:128-152
Timestamp: 2026-01-04T08:01:00.038Z
Learning: In v2/internal/system/system.go, shared functions like checkLibrary are defined without build tags but are only invoked from platform-specific files (system_linux.go, system_windows.go, system_darwin.go) that have build constraints. Reviewers should ensure there are no runtime OS checks in system.go and that platform-specific behavior is controlled via build tags. If runtime switches exist, remove them in favor of compile-time platform constraints to reduce overhead and improve correctness.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: semgrep-cloud-platform/scan

Comment thread v3/pkg/application/webview_window_windows.go
Comment thread v3/pkg/application/webview_window_windows.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @v3/pkg/application/webview_window_windows.go:
- Around line 2119-2129: The injected JS/CSS is being applied twice when
w.parent.options.HTML != "" because chromium.Init(script) in setupChromium()
already injects them, and the navigation handler later re-injects while
webviewNavigationCompleted is still false; to fix, either set
w.webviewNavigationCompleted = true in the HTML branch inside setupChromium()
(the code around setupChromium() / chromium.Init and the HTML path) to avoid the
later injection, or remove the initial injection and consolidate into the
navigation-completion block (the block using w.execJS), and also fix CSS
escaping by replacing the ad-hoc single-quote replace with a robust escape
(e.g., use fmt.Sprintf with %q or a JSON/string encoder) when building the style
script before calling w.execJS.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a679c0d and 677baa1.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_windows.go
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4783
File: v3/pkg/events/events.go:72-100
Timestamp: 2025-12-13T19:52:13.812Z
Learning: In Wails v3, the linux:WindowLoadChanged event was intentionally removed as a breaking change and replaced with four granular WebKit2 load events: linux:WindowLoadStarted, linux:WindowLoadRedirected, linux:WindowLoadCommitted, and linux:WindowLoadFinished. Users should migrate to linux:WindowLoadFinished for detecting when the WebView has finished loading.
📚 Learning: 2025-12-13T19:52:13.812Z
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4783
File: v3/pkg/events/events.go:72-100
Timestamp: 2025-12-13T19:52:13.812Z
Learning: In Wails v3, the linux:WindowLoadChanged event was intentionally removed as a breaking change and replaced with four granular WebKit2 load events: linux:WindowLoadStarted, linux:WindowLoadRedirected, linux:WindowLoadCommitted, and linux:WindowLoadFinished. Users should migrate to linux:WindowLoadFinished for detecting when the WebView has finished loading.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-02-24T06:08:55.645Z
Learnt from: popaprozac
Repo: wailsapp/wails PR: 4098
File: v3/pkg/services/notifications/notifications_windows.go:91-113
Timestamp: 2025-02-24T06:08:55.645Z
Learning: The JSON quote handling in Windows notifications' activation arguments (v3/pkg/services/notifications/notifications_windows.go) has a known limitation with single-quote collisions that needs to be addressed after initial testing.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-08-08T13:15:37.785Z
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4484
File: v2/internal/frontend/utils/urlValidator_test.go:152-155
Timestamp: 2025-08-08T13:15:37.785Z
Learning: In v2/internal/frontend/utils/urlValidator_test.go, the project accepts a literal '|' in the URL path (e.g., "https://example.com/user/123|admin") as valid for BrowserOpenURL. Maintainer (APshenkin) clarified that browsers will escape it automatically; thus, tests should not require percent-encoding '%7C' nor expect an error from utils.ValidateURL for this case. Avoid suggesting rejection or forced encoding of '|' in path in future reviews.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2026-01-04T08:01:00.038Z
Learnt from: symball
Repo: wailsapp/wails PR: 4853
File: v2/internal/system/system.go:128-152
Timestamp: 2026-01-04T08:01:00.038Z
Learning: In v2/internal/system/system.go, shared functions like checkLibrary are defined without build tags but are only invoked from platform-specific files (system_linux.go, system_windows.go, system_darwin.go) that have build constraints. Reviewers should ensure there are no runtime OS checks in system.go and that platform-specific behavior is controlled via build tags. If runtime switches exist, remove them in favor of compile-time platform constraints to reduce overhead and improve correctness.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)

Comment thread v3/pkg/application/webview_window_windows.go
Comment thread v3/pkg/application/webview_window_windows.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @v3/pkg/application/webview_window_windows.go:
- Around line 2111-2114: The JS injection escapes only single quotes and fails
for newlines/backslashes; replace the manual strings.ReplaceAll escaping of
w.parent.options.CSS with proper Go string quoting (use fmt.Sprintf with %q)
when building the js variable so the CSS is safely encoded as a JS string;
update the block that constructs js and calls w.execJS to use
fmt.Sprintf("(function(){...})()", cssQuoted) where cssQuoted is produced via %q
(consistent with setHTML usage) so multiline/backslash characters are handled
correctly.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 677baa1 and c4150b1.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_windows.go
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4783
File: v3/pkg/events/events.go:72-100
Timestamp: 2025-12-13T19:52:13.812Z
Learning: In Wails v3, the linux:WindowLoadChanged event was intentionally removed as a breaking change and replaced with four granular WebKit2 load events: linux:WindowLoadStarted, linux:WindowLoadRedirected, linux:WindowLoadCommitted, and linux:WindowLoadFinished. Users should migrate to linux:WindowLoadFinished for detecting when the WebView has finished loading.
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-12-13T19:52:13.812Z
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4783
File: v3/pkg/events/events.go:72-100
Timestamp: 2025-12-13T19:52:13.812Z
Learning: In Wails v3, the linux:WindowLoadChanged event was intentionally removed as a breaking change and replaced with four granular WebKit2 load events: linux:WindowLoadStarted, linux:WindowLoadRedirected, linux:WindowLoadCommitted, and linux:WindowLoadFinished. Users should migrate to linux:WindowLoadFinished for detecting when the WebView has finished loading.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-08-08T09:13:16.916Z
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-12-29T08:02:15.134Z
Learnt from: popaprozac
Repo: wailsapp/wails PR: 4839
File: docs/src/content/docs/reference/window.mdx:616-620
Timestamp: 2025-12-29T08:02:15.134Z
Learning: In Wails v3, the correct API for creating windows is `app.Window.New()` and `app.Window.NewWithOptions(...)`, not `app.NewWebviewWindow()` or `app.NewWebviewWindowWithOptions(...)`. The Application struct exposes a Window field of type *WindowManager that provides these methods.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-02-24T06:08:55.645Z
Learnt from: popaprozac
Repo: wailsapp/wails PR: 4098
File: v3/pkg/services/notifications/notifications_windows.go:91-113
Timestamp: 2025-02-24T06:08:55.645Z
Learning: The JSON quote handling in Windows notifications' activation arguments (v3/pkg/services/notifications/notifications_windows.go) has a known limitation with single-quote collisions that needs to be addressed after initial testing.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2024-09-20T23:34:29.841Z
Learnt from: nixpare
Repo: wailsapp/wails PR: 3763
File: v3/examples/keybindings/main.go:16-17
Timestamp: 2024-09-20T23:34:29.841Z
Learning: In the codebase, `application.Options.KeyBindings` uses the `application.Window` type, whereas `application.WebviewWindowOptions.KeyBindings` uses `*application.WebviewWindow`. This is intentional and acceptable.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
📚 Learning: 2026-01-04T08:01:00.038Z
Learnt from: symball
Repo: wailsapp/wails PR: 4853
File: v2/internal/system/system.go:128-152
Timestamp: 2026-01-04T08:01:00.038Z
Learning: In v2/internal/system/system.go, shared functions like checkLibrary are defined without build tags but are only invoked from platform-specific files (system_linux.go, system_windows.go, system_darwin.go) that have build constraints. Reviewers should ensure there are no runtime OS checks in system.go and that platform-specific behavior is controlled via build tags. If runtime switches exist, remove them in favor of compile-time platform constraints to reduce overhead and improve correctness.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
v3/pkg/application/webview_window_windows.go (1)

2106-2116: Logic for first-navigation gate is correct.

The guard condition properly ensures user-provided JS and CSS are executed only on the initial navigation, before webviewNavigationCompleted is set to true at line 2126. This aligns with the PR objective to fix the missing execJS call during webview creation.

Comment thread v3/pkg/application/webview_window_windows.go
popaprozac and others added 2 commits January 12, 2026 15:40
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@leaanthony
Copy link
Copy Markdown
Member

That's odd. Any execJS called before the DOM is ready should be buffered and flushed. How did you notice this fail?

@popaprozac
Copy link
Copy Markdown
Contributor Author

popaprozac commented Jan 13, 2026

Sorry I should have been more clear. When setting a JS string in the webview window options upon creation I was finding on Windows it would not execute. My ref to execJS was internal. I tested with something like:

window := app.Window.NewWithOptions(application.WebviewWindowOptions{
    Title:  "My Application",
    URL: "/",
    JS: "window.foo = bar;" <-- here
})

On macOS and Linux, this executes after the initial navigation WebViewDidFinishNavigation and WindowLoadFinished respectively. window.foo is set on the created webview's window. On Windows it was undefined. If I am reading this correctly Windows is only adding the script to be used if options.HTML is set. <- Need to test this when I can

I went to look at the go-webview2 pkg and now see that chromium.Init() should run scripts after the DOM is ready. So I can update this later to either continue to rely on the chromium.Init(), regardless of HTML string being set. Am I missing something?

@popaprozac popaprozac changed the title fix(v3/windows): Fix add missing execJS when webview is created fix(v3/windows): Fix ensure JS string is executed when webview is created Jan 13, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@v3/pkg/application/webview_window_windows.go`:
- Around line 2106-2116: The block that injects JS/CSS when
!w.webviewNavigationCompleted (using w.webviewNavigationCompleted,
w.parent.options.JS, w.parent.options.CSS and w.execJS) has an extra closing
brace '}' after the CSS injection that breaks compilation; remove that stray '}'
so the if-blocks and function braces properly balance, leaving the outer
function and the if !w.webviewNavigationCompleted { ... } block correctly closed
only once.

Comment thread v3/pkg/application/webview_window_windows.go
@sonarqubecloud
Copy link
Copy Markdown

@leaanthony
Copy link
Copy Markdown
Member

Hey @popaprozac! Your PR got me thinking... the injection stuff has always been a bit messy. Now we are using http semantics, whether we could just request these as files at startup. That way we don't have gnarly escape issues and it works the same for all platforms. I've got a PR up here: #4888 and would be interested in your thoughts 👍

@popaprozac
Copy link
Copy Markdown
Contributor Author

Okay sounds great! Will review but seems like a clear improvement

@popaprozac
Copy link
Copy Markdown
Contributor Author

Closing in favor of #4888

@popaprozac popaprozac closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants