Skip to content

Add copy buttons to the network inspector Headers and Cookies tabs - #10052

Open
hkarmoush wants to merge 6 commits into
flutter:masterfrom
hkarmoush:network-inspector-copy
Open

hkarmoush wants to merge 6 commits into
flutter:masterfrom
hkarmoush:network-inspector-copy

Conversation

@hkarmoush

@hkarmoush hkarmoush commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #8190

The Headers and Cookies tabs in the network request inspector had no way to copy their contents, and the cookie table and image metadata weren't selectable at all. This adds a copy button to the tab bar for Headers and Cookies, the same as Request and Response already have, so all the tabs work the same way.

  • Headers copies each section (General, Response Headers, Request Headers) under its title as key: value lines. Multi-value headers are joined the way they'd be sent (set-cookie gets one line per value, cookie is joined with ; ), so the text is easy to paste into a bug report. The General section is printed as plain key: value lines, the same as the tab shows it.
  • Cookies copies response cookies as their raw Set-Cookie values (parsing drops Max-Age and SameSite, so the raw header is used when it's there) and request cookies as a Cookie header value.
  • Cookie cells and image metadata are now inside a SelectionArea. Selection doesn't work in VS Code on Mac (SelectableText and SelectionArea do not work correctly when calling document.execCommand("copy") unless you right-click flutter#182756), which is why the copy buttons are the main fix here.

While in there I also fixed calculateHeadersSize, used for the HAR export. It checked value is List<String>, but headers decoded from JSON are List<dynamic>, so list values were counted with their brackets. It now shares the same formatting as the copy text, so headersSize in exported HAR files changes for requests with multi-value headers (and is now correct for them).

Per-row copy and the request list actions menu mentioned in the issue are left for a follow-up.

Before/after screenshots to come.

Pre-launch Checklist

General checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I updated/added relevant documentation (doc comments with ///).

Issues checklist

Tests checklist

  • I added new tests to check the change I am making...
  • OR there is a reason for not adding tests, which I explained in the PR description.

AI-tooling checklist

  • I did not use any AI tooling in creating this PR.
  • OR I did use AI tooling, and...
    • I read the AI contributions guidelines and agree to follow them.
    • I reviewed all AI-generated code before opening this PR.
    • I understand and am able to discuss the code in this PR.
    • I have verifed the accuracy of any AI-generated text included in the PR description.
    • I commit to verifying the accuracy of any AI-generated code or text that I upload in response to review comments.

Feature-change checklist

  • This PR does not change the DevTools UI or behavior and...
    • I added the release-notes-not-required label or left a comment requesting the label be added.
  • OR this PR does change the DevTools UI or behavior and...
    • I added an entry to packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.
    • I included before/after screenshots and/or a GIF demo of the new UI to my PR description.
    • I ran the DevTools app locally to manually verify my changes.

build.yaml badge

If you need help, consider asking for help on Discord.

@hkarmoush
hkarmoush marked this pull request as ready for review October 24, 2026 10:17
@hkarmoush
hkarmoush requested review from a team, kenzieschmoll and srawlins as code owners October 24, 2026 10:17

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds copy buttons to the Headers and Cookies tabs of the network request inspector, and wraps cookie values and image metadata in SelectionArea to make them selectable. It also refactors the formatting logic for headers and cookies into reusable utility functions in http_utils.dart and adds comprehensive tests. The review feedback suggests improving robustness and idiomatic Dart by checking and casting to Iterable instead of List when handling multi-value headers.

@fkarmoush

Copy link
Copy Markdown

Thanks for picking this up. Making Headers and Cookies copyable the same way as Request and Response closes a gap that's been awkward in the network inspector, and the curl-ready format (one set-cookie line per value, cookie joined with ;) means the copied text is usable as-is in a terminal or bug report. The calculateHeadersSize fix for HAR export is a nice catch too.

Looking forward to seeing this land once it's ready for review.

@srawlins srawlins 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.

Lovely! Thanks for the PR and sorry for the delay. Just a few nits.

List<Cookie> cookies,
Map<String, Object?>? responseHeaders,
) {
final rawCookies = responseHeaders?.entries

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.

I think we can rewrite this to be a little more readable. One, we can handle the null responseHeaders case first, and then can use a for-element and if-elements:

if (responseHeaders == null) {
  return cookies.map(_cookieNameAndValue).join('\n');
}
final rawCookies = [
  for (final MapEntry(:key, :value) in responseHeaders.entries)
    if (key.toLowerCase() == _setCookieHeader)
      if (value is Iterable) ...value
      else value
];

Maybe a little nicer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, went with the null-first for/if version. Kept the fallback to the parsed cookies when there's no set-cookie header.

),
];
return [
for (final (:title, :headers, :format) in sections)

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.

These two list literals, with the second iterating over the first, is pretty unusual. But I think it's pretty elegant. Patterns could make it more concise but maybe not more readable. 🤷

return [
    if (data.general case List(isNotEmpty: true) && final headers)
      '$_generalTitle\n${generalInfoToText(headers)}',
    if (data.responseHeaders case List(isNotEmpty: true) && final headers)
      '$_responseHeadersTitle\n${headersToText(headers)}',
    if (data.requestHeaders case List(isNotEmpty: true) && final headers)
      '$_requestHeadersTitle\n${headersToText(headers)}',
];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, folded it into one list with if-case. Bound general once since that getter builds a new map each time.

The Headers and Cookies tabs now have a copy button in the tab bar, the
same as Request and Response. Headers are copied as key: value lines
under each section title. Response cookies are copied as their raw
Set-Cookie values and request cookies as a Cookie header value.

Cookie values and image metadata are now selectable too.

Also fixes calculateHeadersSize, which never joined list values because
headers decoded from JSON are List<dynamic>, not List<String>.
@hkarmoush
hkarmoush force-pushed the network-inspector-copy branch from 22576a3 to adbdfa7 Compare November 13, 2026 10:48
@hkarmoush

Copy link
Copy Markdown
Contributor Author

Also fixed the DCM avoid-dynamic warnings in the http_utils tests (switched the list literals to <Object?>).

This branch has not been deployed

No deployments
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.

3 participants