Files
readest/apps/readest-app/src/utils/viewport.ts
T
Huang Xin cc8f917cdd fix(layout): silence viewport meta warning on non-Android browsers (#4097)
`interactive-widget=resizes-content` was set in the SSR viewport
metadata so Android Chrome would shrink the layout viewport when
the on-screen keyboard opens (matching iOS default behavior).
Other browsers — Safari on macOS / iOS, desktop Chrome, Firefox —
log a console warning every page load because they don't recognize
the key.

Move the attachment client-side, gated on a UA sniff for Android,
so the meta tag stays clean for everyone else. The Android-specific
behavior (modals centered above the keyboard) is preserved on the
platform that actually needed it.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 21:16:52 +02:00

18 lines
871 B
TypeScript

// `interactive-widget=resizes-content` makes Android Chrome shrink the
// layout viewport when the on-screen keyboard opens, matching iOS
// default behavior so `fixed inset-0`-centered modals (passphrase
// prompt, group picker, etc.) sit above the keyboard. Other browsers
// (Safari on macOS/iOS, desktop Chrome, Firefox) emit a console warning
// when they encounter the unrecognized key on every page load — so we
// only attach it on Android.
export const getAndroidPatchedViewportContent = (
userAgent: string,
currentContent: string,
): string | null => {
if (!/android/i.test(userAgent)) return null;
if (currentContent.includes('interactive-widget=')) return null;
const trimmed = currentContent.trim().replace(/,\s*$/, '');
if (!trimmed) return 'interactive-widget=resizes-content';
return `${trimmed}, interactive-widget=resizes-content`;
};