Skip to content

fix(web): allow to use file URLs on Android#16132

Open
ermshiperete wants to merge 2 commits into
masterfrom
fix/web/16096_blankKeyboard
Open

fix(web): allow to use file URLs on Android#16132
ermshiperete wants to merge 2 commits into
masterfrom
fix/web/16096_blankKeyboard

Conversation

@ermshiperete

@ermshiperete ermshiperete commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This change fixes the blank keyboard problem on Android which was caused by using the Fetch API fetch() function which doesn't support file:// URLs. This change now uses the XMLHttpRequest class instead and sets the necessary flags on the Android side.

For Keyman for Web nothing changes compared to earlier alpha versions, which means that file URLs shouldn't be used.

This change also deletes loadKeyboardHelper.ts which wasn't used anywhere.

Note that this PR only fixes things for Android, but not iOS where we have a similar problem, but which requires a slightly different solution.

Fixes: #16096
Build-bot: skip release:web,android

User Testing

TEST_ANDROID:

  • Install Keyman for Android from this PR
  • Verify that a keyboard properly shows

TEST_WEB:

  • Open KeymanWeb test page, navigate to any test
  • Select a keyboard and verify that it displays the OSK and that the console window doesn't show errors

@github-project-automation github-project-automation Bot moved this to Todo in Keyman Jun 23, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added the user-test-missing User tests have not yet been defined for the PR label Jun 23, 2026
@keymanapp-test-bot

keymanapp-test-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

resolve(new Response(httpRequest.response, { status: httpRequest.status }))
};
httpRequest.onerror = function () {
reject(new TypeError('Local request failed'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we capture the error which is passed in here -- it's an Event object but there should be some error data somewhere there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Although it doesn't seem that we get error data - e is of type ProgressEvent wich derives from Event, and neither has any error data.

* limitation of the Fetch API fetch(). On Android we still have to
* explicitly allow file URLs.
*/
private fetch(uri: string): Promise<Response> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer to use this only in the Android and iOS apps (WebView) and not the Browser version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Although probably need to be refined when we implement the fix for iOS.

Comment on lines +268 to +269
getSettings().setAllowFileAccessFromFileURLs(true);
getSettings().setAllowUniversalAccessFromFileURLs(true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a comment on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Turns out we don't need setAllowUniversalAccessFromFileURLs. Added a comment for the other line.

Comment thread web/src/engine/src/keyboard/keyboards/loaders/domKeyboardLoader.ts Outdated
@mcdurdin

Copy link
Copy Markdown
Member

Can confirm this fix does not currently work on iOS.

This change fixes the blank keyboard problem on Android and iOS which
was caused by using the Fetch API fetch() function which doesn't support
file:// URLs. This change now uses the `XMLHttpRequest` class instead
and sets the necessary flags on the Android side.

For Keyman for Web nothing changes compared to earlier alpha versions,
which means that file URLs shouldn't be used.

This change also deletes `loadKeyboardHelper.ts` which wasn't used
anywhere.

Co-authored-by: Marc Durdin <marc@durdin.net>

Fixes: #16096
Build-bot: release
@ermshiperete ermshiperete force-pushed the fix/web/16096_blankKeyboard branch from e225015 to 0fd21c0 Compare June 24, 2026 13:21
@ermshiperete ermshiperete changed the title fix(web): allow to use file URLs on Android and iOS fix(web): allow to use file URLs on Android Jun 24, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels Jun 24, 2026
This change adds a `fetchKeyboardFunc` to `DOMKeyboardLoader` that allows
mobile platforms to use a different method to fetch the keyboard data.
WebView's `KeymanEngine` implements fetching the URL by using
`XMLHttpRequest`.
@ermshiperete ermshiperete force-pushed the fix/web/16096_blankKeyboard branch from eadcbe9 to 79fd7c8 Compare June 24, 2026 17:19
@ermshiperete ermshiperete marked this pull request as ready for review June 24, 2026 17:21
@ermshiperete ermshiperete requested a review from jahorton June 24, 2026 17:24
@Meng-Heng Meng-Heng self-assigned this Jun 25, 2026
@Meng-Heng

Copy link
Copy Markdown
Contributor

Test Results

  • TEST_ANDROID (PASSED):
  1. Launch Android Studio, Pixel 9 API 35 Emulator
  2. Drag and drop keyman-19.0.248-alpha-test-16132
  3. Launch Keyman within the Emulator
  4. The Euro Latin (SIL) keyboard displays without any error messages
  5. Predictive text and typing works as expected
  6. Navigate to Settings -> Install Keyboard or Dictionary -> Install from keyman.com -> Install Khmer Angkor keyboard
  7. The process of downloading the keyboard work as expected
  8. Khmer Angkor keyboard displays and types without any error messages
  9. Switching keyboards work as expected.
  • TEST_WEB (PASSED):
  1. Navigate to the Web Test page for Keymanweb_TestPullRequests/630412
  2. View KeymanWeb use samples ->Example 1 - Toggle UI, all resources in same folder as page -> Keyboard switches and types
  3. View Keymanweb website-oriented manual test pages -> Prediction - robust testing (prediction-mtnt) -> Keyboard switches and types + predictive text works as expected.

Note

The Test Artifacts link for Android does not work, instead I navigated to the apk through the Test checks links.

@keymanapp-test-bot keymanapp-test-bot Bot removed the user-test-required User tests have not been completed label Jun 25, 2026
@Meng-Heng Meng-Heng removed their assignment Jun 25, 2026

@mcdurdin mcdurdin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is definitely a straightforward patch; can we refactor it to be more object-oriented given our existing pattern with KeymanEngine: KeymanEngineBase?

Will we need to do similar work for fonts and lexical models?

* Fetch API's fetch() which doesn't support file:// URLs. At least in
* Keyman for Android we still have to explicitly allow file URLs.
*/
private fetch(uri: string): Promise<Response> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to have this designed as a protected function in KeymanEngineBase which we override here, in KeymanEngineBase.ts it would be something like:

protected fetch(uri: string): Promise<Response> {
  throw new Error('not implemented');
}

and in browser/src/KeymanEngine.ts:

protected fetch(uri: string): Promise<Response> {
  return window.fetch(uri);
}

and then this would also be protected.

That moves the responsibility for defining what fetch does into the same place for both WebView and Browser components.

@mcdurdin

mcdurdin commented Jun 25, 2026

Copy link
Copy Markdown
Member

The Test Artifacts link for Android does not work, instead I navigated to the apk through the Test checks links.

Tracking this in #16137 -- we were planning for Android test PRs to include the full tag in the file name:

  • keyman-19.0.248-alpha-test-16132.apk vs
  • keyman-19.0.248.apk

Note that the 'Keyman for Android apk (old PRs)' link currently works in the Test Artifacts list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

bug(web): blank keyboard after installing Keyman for Android or Keyman for iOS 19.0.242 or later

3 participants