Skip to content

Commit c3e5678

Browse files
committed
Merge branch 'main' into feat/input-translation-triple-space
2 parents e2a4d54 + 33acbfc commit c3e5678

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

.changeset/seven-waves-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@read-frog/extension": patch
3+
---
4+
5+
fix: ensure language detection only occurs in the top frame to prevent race conditions with iframes

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Check out the [Contribution Guide](https://readfrog.app/en/tutorial/code-contrib
261261
<br>
262262
</th>
263263
</tr>
264-
<tr>
264+
<!-- <tr>
265265
<td>
266266
<picture>
267267
<source media="(prefers-color-scheme: dark)" srcset="https://next.ossinsight.io/widgets/official/compose-recent-top-contributors/thumbnail.png?repo_id=967738751&image_size=auto&color_scheme=dark" width="373" height="auto">
@@ -274,7 +274,7 @@ Check out the [Contribution Guide](https://readfrog.app/en/tutorial/code-contrib
274274
<img alt="Performance Stats of mengxi-ream/read-frog - Last 28 days" src="https://next.ossinsight.io/widgets/official/compose-last-28-days-stats/thumbnail.png?repo_id=967738751&image_size=auto&color_scheme=light" width="655" height="auto">
275275
</picture>
276276
</td>
277-
</tr>
277+
</tr> -->
278278
</table>
279279
</a>
280280

README.zh-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Read Frog 的愿景是为各个级别的语言学习者提供易于使用、智
259259
<br>
260260
</th>
261261
</tr>
262-
<tr>
262+
<!-- <tr>
263263
<td>
264264
<picture>
265265
<source media="(prefers-color-scheme: dark)" srcset="https://next.ossinsight.io/widgets/official/compose-recent-top-contributors/thumbnail.png?repo_id=967738751&image_size=auto&color_scheme=dark" width="373" height="auto">
@@ -272,7 +272,7 @@ Read Frog 的愿景是为各个级别的语言学习者提供易于使用、智
272272
<img alt="Performance Stats of mengxi-ream/read-frog - Last 28 days" src="https://next.ossinsight.io/widgets/official/compose-last-28-days-stats/thumbnail.png?repo_id=967738751&image_size=auto&color_scheme=light" width="655" height="auto">
273273
</picture>
274274
</td>
275-
</tr>
275+
</tr> -->
276276
</table>
277277
</a>
278278

src/entrypoints/host.content/index.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ export default defineContentScript({
9898
if (manager.isActive) {
9999
manager.stop()
100100
}
101-
const { detectedCodeOrUnd } = await getDocumentInfo()
102-
const detectedCode: LangCodeISO6393 = detectedCodeOrUnd === 'und' ? 'eng' : detectedCodeOrUnd
103-
await storage.setItem<LangCodeISO6393>(`local:${DETECTED_CODE_STORAGE_KEY}`, detectedCode)
104-
// Notify background script that URL has changed, let it decide whether to automatically enable translation
105-
void sendMessage('checkAndAskAutoPageTranslation', { url: to, detectedCodeOrUnd })
101+
// Only the top frame should detect and set language to avoid race conditions from iframes
102+
if (window === window.top) {
103+
const { detectedCodeOrUnd } = await getDocumentInfo()
104+
const detectedCode: LangCodeISO6393 = detectedCodeOrUnd === 'und' ? 'eng' : detectedCodeOrUnd
105+
await storage.setItem<LangCodeISO6393>(`local:${DETECTED_CODE_STORAGE_KEY}`, detectedCode)
106+
// Notify background script that URL has changed, let it decide whether to automatically enable translation
107+
void sendMessage('checkAndAskAutoPageTranslation', { url: to, detectedCodeOrUnd })
108+
}
106109
}
107110
}
108111

@@ -129,11 +132,14 @@ export default defineContentScript({
129132
enabled ? void manager.start() : manager.stop()
130133
})
131134

132-
const { detectedCodeOrUnd } = await getDocumentInfo()
133-
const initialDetectedCode: LangCodeISO6393 = detectedCodeOrUnd === 'und' ? 'eng' : detectedCodeOrUnd
134-
await storage.setItem<LangCodeISO6393>(`local:${DETECTED_CODE_STORAGE_KEY}`, initialDetectedCode)
135+
// Only the top frame should detect and set language to avoid race conditions from iframes
136+
if (window === window.top) {
137+
const { detectedCodeOrUnd } = await getDocumentInfo()
138+
const initialDetectedCode: LangCodeISO6393 = detectedCodeOrUnd === 'und' ? 'eng' : detectedCodeOrUnd
139+
await storage.setItem<LangCodeISO6393>(`local:${DETECTED_CODE_STORAGE_KEY}`, initialDetectedCode)
135140

136-
// Check if auto-translation should be enabled for initial page load
137-
void sendMessage('checkAndAskAutoPageTranslation', { url: window.location.href, detectedCodeOrUnd })
141+
// Check if auto-translation should be enabled for initial page load
142+
void sendMessage('checkAndAskAutoPageTranslation', { url: window.location.href, detectedCodeOrUnd })
143+
}
138144
},
139145
})

0 commit comments

Comments
 (0)