cherry-studio/packages
Copilot a91c69982c
feat: Add print to PDF and save as HTML for mini program webviews (#11104)
* Initial plan

*  feat: Add print to PDF and save as HTML for mini program webviews

- Add IPC channels for Webview_PrintToPDF and Webview_SaveAsHTML
- Implement printWebviewToPDF and saveWebviewAsHTML functions in WebviewService
- Add keyboard shortcuts handlers (Cmd/Ctrl+P for print, Cmd/Ctrl+S for save)
- Update WebviewContainer to handle keyboard shortcuts and trigger print/save actions
- Add preload API methods for webview print and save operations

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* ♻️ refactor: Improve webview ID handling and remove unused import

- Get webviewId dynamically when shortcuts are triggered instead of caching
- Remove unused 'join' import from WebviewService
- Add null check for webviewId in shortcut handler

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* 🐛 fix: Improve doctype serialization for better cross-browser compatibility

- Use direct DOCTYPE construction instead of XMLSerializer
- More reliable across different browser contexts
- Based on code review feedback

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

*  enhance: Complete DOCTYPE support with publicId and systemId

- Add full DOCTYPE construction including publicId and systemId
- Fix grammar in comment (custom -> with custom logic)
- Ensures proper HTML5 and XHTML document types are preserved

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* 🔒 security: Add input validation and improve code structure

- Extract shortcut checking logic into isHandledShortcut helper
- Add try-catch in executeJavaScript for safety
- Escape quotes in DOCTYPE publicId and systemId
- Add optional chaining for documentElement
- Provide fallback if doctype properties are unexpected

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* 🐛 fix: Correct DOCTYPE declaration format and quote escaping

- Use single quotes and proper escaping for DOCTYPE attributes
- Add SYSTEM keyword for systemId-only cases
- Ensure PUBLIC is only used with publicId
- Fix quote escaping to use backslashes instead of HTML entities
- Properly handle all DOCTYPE declaration formats per HTML/SGML spec

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* 🐛 fix: Correct JavaScript string escaping for quotes

- Fix quote escaping from \\\\\' to \\'
- Ensures proper backslash escaping in JavaScript template string
- Produces correct \' in the final DOCTYPE string

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* fix(i18n): Auto update translations for PR #11104

*  enhance: Use page title for default filename and improve PDF pagination

- Get page title from webview and use it as default filename for both PDF and HTML export
- Sanitize filename by removing invalid characters and limiting length
- Add preferCSSPageSize option to printToPDF for better multi-page support
- Fallback to timestamp-based filename if title is unavailable

Addresses reviewer feedback and fixes PDF export only capturing first page issue.

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

* 🎨 style: Fix formatting issues

- Remove trailing whitespace in WebviewContainer.tsx
- Run biome format and lint to ensure code style compliance

Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: SuYao <sy20010504@gmail.com>
2025-12-11 16:42:33 +08:00
..
ai-sdk-provider fix: update deepseek logic to match deepseek v3.2 (#11648) 2025-12-04 19:13:51 +08:00
aiCore feat: enhance web search tool switching logic to support provider-specific context (#11769) 2025-12-11 15:01:01 +08:00
extension-table-plus chore[lint]: add import type lint (#11091) 2025-11-01 10:40:02 +08:00
mcp-trace chore[lint]: add import type lint (#11091) 2025-11-01 10:40:02 +08:00
shared feat: Add print to PDF and save as HTML for mini program webviews (#11104) 2025-12-11 16:42:33 +08:00