Skip to content

Conversation

@cheack
Copy link
Contributor

@cheack cheack commented Jan 24, 2026

This PR fixes an issue where "Screenshot Mode" did not hide or blur text inside email body iframes.

  • Added ScreenshotModeMessageExtension (using MessageViewExtension) to inject styles into email body iframes upon rendering.
  • Hide the email subject from the window title while screenshot mode is active.

Before
Screenshot_20260124_095901

After
image

@indent-staging
Copy link
Contributor

indent-staging bot commented Jan 24, 2026

Issues

2 potential issues found:

  • Autofix getStyleText() performs synchronous file I/O on every call to applyToDocument. Since the CSS content is static, it could be cached in a module-level variable for better performance.
  • Autofix applyToDocument accesses doc.head without a null check. If called on a document without a head element (e.g., a third-party iframe), doc.head.appendChild(el) will throw a TypeError.

Summary

This PR extends screenshot mode to properly obscure email content by applying the screenshot-mode CSS to email body iframes (not just the main document) and hiding the email subject from the window title.

  • Registers a MessageViewExtension to apply screenshot-mode styles to newly rendered email bodies in iframes
  • Patches window.setTitle to show only "Mailspring" (without subject) when screenshot mode is enabled
  • Iterates existing iframes on toggle to apply/remove styles from all visible email content
  • Properly cleans up extension registration and title patching on deactivate

CI Checks

Waiting for CI checks...

Rule Checks 3 rules evaluated, 3 passed, 0 failed

Passing rules

Passing C
Passing B
Passing Ben Rule

Autofix All

el = doc.createElement('style');
el.id = 'screenshot-mode-styles';
el.innerText = getStyleText();
doc.head.appendChild(el);
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential null reference: doc.head could be null for documents without a head element (e.g., third-party iframes). While unlikely in practice since email iframes are created with doc.write() which includes a DOCTYPE, adding a guard would make this more robust: if (doc.head) { doc.head.appendChild(el); }

return 'Mailspring' + (thread ? ' · ' + thread.subject : '');
}

function getStyleText() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor performance optimization: This reads the CSS file synchronously on every call, which happens on toggle and for every new message rendered. Consider caching the result in a module-level variable since the CSS content is static.

@bengotow
Copy link
Collaborator

I think this will resolve #1044!

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