Skip to content

Commit cb372fc

Browse files
chaxusclaude
andcommitted
fix: guard document/window access in I18n to prevent Node.js crash
getCookie() accesses document.cookie and getUrlParameter() accesses window.location via ranuts utilities. When Playwright imports @bybrowser/editor in Node.js (for onlyoffice-new-document.spec.ts), the module-level `new I18n()` call crashes with 'ReferenceError: document is not defined'. Add typeof guards so both methods return null safely in SSR/Node.js environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 58e2ee4 commit cb372fc

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎packages/editor-v7/src/i18n.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ class I18n {
131131
* Get cookie value by name (using ranuts utility)
132132
*/
133133
private getCookie(name: string): string | null {
134+
if (typeof document === 'undefined') return null;
134135
return getCookie(name);
135136
}
136137

137138
/**
138139
* Get URL parameter by name (using ranuts utility)
139140
*/
140141
private getUrlParameter(name: string): string | null {
142+
if (typeof window === 'undefined') return null;
141143
return getQuery()?.[name] || null;
142144
}
143145

‎packages/editor-v9/src/i18n.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ class I18n {
131131
* Get cookie value by name (using ranuts utility)
132132
*/
133133
private getCookie(name: string): string | null {
134+
if (typeof document === 'undefined') return null;
134135
return getCookie(name);
135136
}
136137

137138
/**
138139
* Get URL parameter by name (using ranuts utility)
139140
*/
140141
private getUrlParameter(name: string): string | null {
142+
if (typeof window === 'undefined') return null;
141143
return getQuery()?.[name] || null;
142144
}
143145

0 commit comments

Comments
 (0)