Expand my Community achievements bar.

AEM Forms App MobileWorkspace: Running APK in Emulator throwing "Uncaught TypeError: text.replaceAll is not a function"

Avatar

Level 1

Using adobe-lc-mobileworkspace-src-2.5.22 APK (AEM Forms App)

Android Studio Hedgehog | 2023.1.1 Patch 1 running on Windows 10 Desktop

Galaxy Tab S7 FE API 33 (Emulator) - We use that Tablet for our application (our employees)

 

I had to futz with the Gradle version (upgraded to 4.10.3/3.3.3) to get the APK to build - compatibility with Android Studio - but seems fine.

 

When accessing one of start points (that has been unmodified for several years) and works fine using the standard APK on our existing tablets... I get this error.

 

[INFO:CONSOLE(39890)] "Uncaught TypeError: text.replaceAll is not a function", source: http://fincare-dev.healthcareit.net:8080/lc/etc.clientlibs/fd/xfaforms/clientlibs/profile.js (39890)

 

The cordova.js has a standard fix (shim of sorts)

if(typeof String.prototype.replaceAll === "undefined") {
String.prototype.replaceAll = function(match, replace) {
return this.replace(new RegExp(match, 'g'), () => replace);
}
}
 
But obviously not seen by the mobile workspace in this context.
The profile.js appears to be some generated file by AEM that jams a bunch of stuff together.
 
Anyone have any ideas as to root cause and hence a way to the fix? Is it an Emulator issue? Is it something that I can fix server or client side???
3 Replies

Avatar

Community Advisor

Hi @RobinJo2 
I am not aware about solving issues for a device emulator. I think you can go for a general solution here so that you don't face above issue at other devices.
In these cases where advance/ or relatively new methods don't work. We can use 
1. Polyfills
Install as a dependency with npm i string.prototype.replaceall or yarn add string.prototype.replaceall;

Add the following code in your project. It need to be added in one place only.

import replaceAllInserter from 'string.prototype.replaceall';

replaceAllInserter.shim();
Checkout if you can find some workable solution here : https://stackoverflow.com/questions/62825358/javascript-replaceall-is-not-a-function-type-error/7004...

2. Use original replace method :
https://dmitripavlutin.com/replace-all-string-occurrences-javascript/

 

Avatar

Level 1

I rebuilt my Emulator making sure it was Android 13 API 33 - I had select Android 11 API 30.

And lo and behold the problem vanished.

I blame Android madness.

Avatar

Administrator

@RobinJo2 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni