Skip to content

Commit

Permalink
fix(android): make JSInjector replace first <head> only (#7249)
Browse files Browse the repository at this point in the history
Co-authored-by: Spenser Jones <[email protected]>
  • Loading branch information
jcesarmobile and SpenserJ authored Feb 13, 2024
1 parent 4650b4f commit 1c45b81
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public String getScriptString() {
* @return
*/
public InputStream getInjectedStream(InputStream responseStream) {
String js = "<script type=\"text/javascript\">" + getScriptString() + "</script>";
String js = "<script type=\"text/javascript\">" + getScriptString().replace("${", "\\${") + "</script>";
String html = this.readAssetStream(responseStream);
if (html.contains("<head>")) {
html = html.replace("<head>", "<head>\n" + js + "\n");
html = html.replaceFirst("<head>", "<head>\n" + js + "\n");
} else if (html.contains("</head>")) {
html = html.replace("</head>", js + "\n" + "</head>");
html = html.replaceFirst("</head>", js + "\n" + "</head>");
} else {
Logger.error("Unable to inject Capacitor, Plugins won't work");
}
Expand Down

0 comments on commit 1c45b81

Please sign in to comment.