Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where pages can disable translation via html tags and the o… #27836

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

Brandon-T
Copy link
Contributor

Summary

  • Detect when the translation for a page isn't fully loaded yet, such as on Google where the page loads entirely in Javascript first, then that Javascript dynamically loads the HTML
  • Fix translation Onboarding showing up on a page where it's not supported (Cannot translate English to English).
  • Fix translation Onboarding crash when tapping the icon in the URL-Bar

Resolves brave/brave-browser#44272

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@Brandon-T Brandon-T added CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64 CI/skip-macos-arm64 Do not run CI builds for macOS arm64 CI/skip-teamcity Do not run builds in TeamCity labels Feb 26, 2025
@Brandon-T Brandon-T self-assigned this Feb 26, 2025
@Brandon-T Brandon-T requested a review from a team as a code owner February 26, 2025 23:19
@@ -325,6 +325,12 @@ class BraveTranslateTabHelper: NSObject {
state: isTranslationSupported ? .available : .unavailable
)

// Translation is not supported on this page, so do not show onboarding
// Return immediately
if !isTranslationSupported {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sure we don't translate from en to en for example. So a page cannot be translated if it's already in your desired language.

@@ -86,7 +86,6 @@ extension BrowserViewController: BraveTranslateScriptHandlerDelegate {
action: { popover in
popover.previewForOrigin = nil
popover.dismissPopover()
completion(nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes the CheckedContinuation crash. dismissPopover already calls the completion

setTimeout(function() {
try {
try {
if ((cr.googleTranslate.libReady || cr.googleTranslate.finished) && !cr.googleTranslate.readyCallback) {
Copy link
Contributor Author

@Brandon-T Brandon-T Feb 26, 2025

Choose a reason for hiding this comment

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

This fixes the Onboarding button sometimes showing as if it's blended with reader-mode or in the wrong spot. It's because the page isn't ready to be translated yet, so onboarding showed up early.

The timeout didn't help, so it's removed in favour of just checking if the script is ready.

…nboarding showed up. Fixed a bug where translate popup showed up when the script wasn't ready. Fixed a crash in PopoverController usage calling CheckedContinuation twice.
@Brandon-T Brandon-T force-pushed the bugfix/TranslationDisabledFixes branch from 7af8d22 to c6d35b6 Compare February 27, 2025 18:40
@Brandon-T Brandon-T merged commit b2ba2dc into master Feb 27, 2025
18 checks passed
@Brandon-T Brandon-T deleted the bugfix/TranslationDisabledFixes branch February 27, 2025 20:59
@github-actions github-actions bot added this to the 1.78.x - Nightly milestone Feb 27, 2025
@brave-builds
Copy link
Collaborator

Released in v1.78.4

Brandon-T added a commit that referenced this pull request Feb 28, 2025
* Fix a bug where pages can disable translation via html tags and the onboarding showed up.
* Fixed a bug where translate popup showed up when the script wasn't ready.
* Fixed a crash in PopoverController usage calling CheckedContinuation twice.
Brandon-T added a commit that referenced this pull request Feb 28, 2025
* Fix a bug where pages can disable translation via html tags and the onboarding showed up.
* Fixed a bug where translate popup showed up when the script wasn't ready.
* Fixed a crash in PopoverController usage calling CheckedContinuation twice.
Brandon-T added a commit that referenced this pull request Feb 28, 2025
* Fix a bug where pages can disable translation via html tags and the onboarding showed up.
* Fixed a bug where translate popup showed up when the script wasn't ready.
* Fixed a crash in PopoverController usage calling CheckedContinuation twice.
Brandon-T added a commit that referenced this pull request Feb 28, 2025
* Fix a bug where pages can disable translation via html tags and the onboarding showed up.
* Fixed a bug where translate popup showed up when the script wasn't ready.
* Fixed a crash in PopoverController usage calling CheckedContinuation twice.
@hffvld
Copy link
Collaborator

hffvld commented Mar 1, 2025

Verified on iPhone 14 and iPad Mini (6th gen) using version(s):

Device/OS: 
- iPhone 14 / iOS 17.7.2
- iPad Mini (6th gen) / iPadOS 18.3
Brave build: 1.78 (6)
BraveCore: 1.78.6 (134.0.6998.39)

Translate Onboarding pop-up

STEPS:

  1. Fresh Install Brave
  2. Open a brand new tab
  3. Tap on the URL Bar
  4. Type: Wiki
  5. Tap on the Google icon in the quick-search to search with the Google search engine > Verify

ACTUAL RESULTS:

  • Verified that the Translate onboarding pop-up is not shown on the incorrect page.

Reproduced with 1.77(70)

iPhone 14 iPad Mini
1 2

Verified with 1.78 (6)

iPhone 14 iPad Mini
Screencast Screencast
1 2
Brave crash

STEPS:

  1. Fresh Install Brave
  2. Open a brand new tab
  3. Tap on Wikipedia thumbnail
  4. Tap on Russian, Japanese, Spanish or another language that is NOT the same as the system language
  5. Translate Onboarding pop-up shows
  6. Tap on the highlighted icon in the URL Search Bar > Verify

ACTUAL RESULTS:

  • Verified that Brave doesn't crash if tapping Translate Onboarding pop-up.

iPhone 14 iPad Mini
Screencast Screencast
1 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-macos-arm64 Do not run CI builds for macOS arm64 CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-teamcity Do not run builds in TeamCity CI/skip-windows-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] - Translate Onboarding Issues
4 participants