Skip to content

Web: Interactive content views - #8515

Open
lups2000 wants to merge 7 commits into
mitmproxy:mainfrom
lups2000:interactive-content-views
Open

lups2000 wants to merge 7 commits into
mitmproxy:mainfrom
lups2000:interactive-content-views

Conversation

@lups2000

@lups2000 lups2000 commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Description

This PR revives what I started back then in #7750.
To summarise:

  • Made HTTP content views editable inline with a live CodeMirror editor, replacing the view/edit toggle.
  • Added inline save: Save button, unsaved-changes dot, and Cmd/Ctrl+S shortcut.
  • Removed "Show more" / line cutoff; full content now shown. WebSocket/TCP messages render read-only in the editor.
  • Polished the editor panel (frame, focus ring, themed gutters/cursor) and removed the dead CodeMirror 5 CSS.

Let me know your thoughts :)

CC: @sleeyax @mhils

Screenshot 2026-10-24 at 11 45 47 Screenshot 2026-10-24 at 11 46 13 Screenshot 2026-10-24 at 11 46 24

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@lups2000
lups2000 requested a review from sleeyax October 24, 2026 09:53
@lups2000 lups2000 mentioned this pull request Oct 25, 2026
1 of 7 tasks

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

Really nice to see this picked back up, the inline editing feels a lot better than the old toggle 🙂

I left a few AI-assisted review comments.

Comment on lines +46 to +53
const saveContent = useCallback(() => {
if (editedContent === undefined) return;
dispatch(
flowActions.update(flow, {
[part]: { content: editedContent },
}),
);
}, [dispatch, flow, part, editedContent]);

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.

The editor shows contentViewData.text, which is the output of the selected view, and this PUTs that text back as the body. On the backend FlowHandler.put just does request.text = v / response.text = v, with no re-encoding. The old edit mode loaded content.data (the raw bytes), so it didn't have this problem.

Some ways this could break:

  • An image in Auto view shows its YAML metadata, so editing one character and saving replaces the PNG with YAML.
  • URL-encoded, multipart, protobuf, msgpack and hex dump views, and prettified JSON/JS/CSS, all save their display form instead of the original encoding.
  • Raw view escapes control characters, so binary bodies get mangled too.
  • Error output ("Couldn't parse as …", "Network Error") can also be edited and saved.

The console UI handles this by only allowing edits for an InteractiveContentview and saving through contentviews.reencode_message (see consoleaddons.py). I think we need the same here: a view-aware save endpoint, plus readonly on the editor for views that aren't interactive and for SyntaxHighlight.ERROR.

Also a smaller one: this only checks editedContent === undefined, not isEdited, so typing a character, deleting it and pressing Ctrl+S still sends a PUT.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this is definitely the main thing to consider. Should we implement the decode/encode functions on the backend? @mhils what do you think?

Comment on lines +41 to +44
// Drop local edits when the underlying content changes.
useEffect(() => {
setEditedContent(undefined);
}, [contentView, message.contentHash, flow.id, part]);

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.

Two ways this can lose edits:

  1. Switching views while there are unsaved changes throws them away without a warning, since the key includes contentView as well.
  2. Saving and then continuing to type: once the flow update comes in, contentHash changes, this resets editedContent, and the refetched text gets pushed into the editor that's still mounted through value. Anything typed after the save is overwritten.

For (1), maybe disable the view selector or ask for confirmation while isEdited. For (2), keep the submitted text in a ref and only reset when the incoming text matches it.

Comment thread web/src/js/flow/utils.ts
(view
? `content/${encodeURIComponent(view)}.json${lineStr}`
: "content.data")
(view ? `content/${encodeURIComponent(view)}.json` : "content.data")

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.

Removing ?lines= means the web UI no longer respects content_view_lines_cutoff at all, so every body is fetched and loaded into the editor in full just by selecting a flow. With large or minified payloads that's going to hurt, and that option exists specifically "to speedup flows browsing".

Could we keep the cutoff for the initial load, and only fetch the full content once someone starts editing or clicks something like "Load full content"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mhils thoughts on this? I remember seeing a discussion about this somewhere (maybe on Discord), where we were considering removing the "show more" thingy and displaying the content directly, since CodeMirror 6 is more efficient. What do you think?

Comment on lines +60 to 64
<CodeEditor
content={d.text}
maxLines={remainingLines}
showMore={showMore}
language={d.syntax_highlight}
readonly
/>

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.

For WebSocket/TCP flows this now mounts a separate CodeMirror instance for every message, with no cap. On top of that, useContentView is keyed on messages_meta.count, so a live connection refetches the entire uncapped history every time a message comes in. A long-running socket with a few thousand messages is going to get very heavy.

Maybe keep a cap plus "show more" for messages, or virtualise the list?

@lups2000
lups2000 requested a balanced review from Copilot November 14, 2026 17:40

This comment was marked as spam.

@lups2000
lups2000 requested a review from mhils November 14, 2026 17:40

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