Skip to content

Expose a generic callDevToolsProtocolMethod on WebviewController - #332

Open
diligent176 wants to merge 1 commit into
jnschulze:mainfrom
diligent176:upstream/call-devtools-protocol-method
Open

diligent176 wants to merge 1 commit into
jnschulze:mainfrom
diligent176:upstream/call-devtools-protocol-method

Conversation

@diligent176

@diligent176 diligent176 commented Aug 20, 2026 •

Copy link
Copy Markdown

webview_windows currently surfaces no way to read or write cookies, and no general escape hatch to the Chrome DevTools Protocol. executeScript cannot fill the gap either: HttpOnly cookies are invisible to document.cookie, which is exactly the class of cookie that matters when driving a signed-in session.

The plugin already calls ICoreWebView2::CallDevToolsProtocolMethod internally - clearCookies() is Network.clearBrowserCookies and clearCache() is Network.clearBrowserCache. This PR exposes the general form of that call. Unlike those two fire-and-forget helpers, it returns the JSON result object, which is what makes read operations such as Storage.getCookies possible.

final json = await controller.callDevToolsProtocolMethod(
  'Storage.getCookies',
  '{}',
);
// {"cookies":[{"name":"...","value":"...","domain":"...","httpOnly":true,...}]}

Why this rather than a cookie API

There are already several requests and PRs for cookie access (#221, #256, #299). ICoreWebView2CookieManager is the idiomatic route for those, and if you'd prefer to expose it directly that is clearly the better-typed answer - I'm not arguing against it.

The case for this one is scope. It's ~100 lines that cover reading cookies, writing cookies, and every other CDP domain, without committing the plugin to a cookie model it then has to maintain and version. It also preserves the full cookie record - domain, path, expires, httpOnly, secure, sameSite - because callers get the raw CDP result rather than a flattened representation. If a first-class CookieManager API lands later, this stays useful and doesn't conflict with it.

Changes

  • lib/src/webview.dart - callDevToolsProtocolMethod(String method, [String parametersAsJson = '{}']), returning Future<String?>, with the same _isDisposed / value.isInitialized guards the neighbouring methods use.
  • windows/webview.cc / webview.h - CallDevToolsProtocolMethod on Webview, taking a completion callback that receives the returned JSON.
  • windows/webview_bridge.cc - method-channel handler, mirroring the existing argument-validation and error-reply style.
  • CHANGELOG.md - an Unreleased entry. Happy to drop this if you'd rather write changelog entries at release time.

Additive only - no existing behaviour or public API is changed.

Testing

The example app builds on Windows (the CI job here). The change has been running in a shipping Flutter desktop app for several weeks, using Storage.getCookies and Storage.setCookies against a live WebView2 session.

Happy to adjust the naming, the parameter shape (a Map instead of a JSON string), or the return type if you'd prefer something different.

This plugin surfaces no cookie API, so the Chrome DevTools Protocol is
currently the only route to operations such as Storage.getCookies /
Storage.setCookies. clearCookies() and clearCache() already call
CallDevToolsProtocolMethod internally; this exposes the general form and,
unlike those two fire-and-forget helpers, returns the JSON result object.
@diligent176
diligent176 force-pushed the upstream/call-devtools-protocol-method branch from 8bb7117 to 79f92ce Compare August 20, 2026 13:02
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.

1 participant