@capacitor/android 5.7.1 → 5.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -142,11 +142,14 @@ var nativeBridge = (function (exports) {
142
142
  var _a, _b;
143
143
  if (isRelativeOrProxyUrl(url))
144
144
  return url;
145
- let proxyUrl = new URL(url);
145
+ const proxyUrl = new URL(url);
146
+ const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
146
147
  const isHttps = proxyUrl.protocol === 'https:';
147
148
  const originalHost = encodeURIComponent(proxyUrl.host);
148
149
  const originalPathname = proxyUrl.pathname;
149
- proxyUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
150
+ proxyUrl.protocol = bridgeUrl.protocol;
151
+ proxyUrl.hostname = bridgeUrl.hostname;
152
+ proxyUrl.port = bridgeUrl.port;
150
153
  proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`;
151
154
  return proxyUrl.toString();
152
155
  };
@@ -501,9 +504,13 @@ var nativeBridge = (function (exports) {
501
504
  options.method.toLocaleUpperCase() === 'HEAD' ||
502
505
  options.method.toLocaleUpperCase() === 'OPTIONS' ||
503
506
  options.method.toLocaleUpperCase() === 'TRACE') {
504
- const modifiedResource = createProxyUrl(resource.toString(), win);
505
- const response = await win.CapacitorWebFetch(modifiedResource, options);
506
- return response;
507
+ if (typeof resource === 'string') {
508
+ return await win.CapacitorWebFetch(createProxyUrl(resource, win), options);
509
+ }
510
+ else if (resource instanceof Request) {
511
+ const modifiedRequest = new Request(createProxyUrl(resource.url, win), resource);
512
+ return await win.CapacitorWebFetch(modifiedRequest, options);
513
+ }
507
514
  }
508
515
  const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
509
516
  console.time(tag);
@@ -69,12 +69,17 @@ class JSInjector {
69
69
  * @return
70
70
  */
71
71
  public InputStream getInjectedStream(InputStream responseStream) {
72
- String js = "<script type=\"text/javascript\">" + getScriptString().replace("${", "\\${") + "</script>";
72
+ String js = "<script type=\"text/javascript\">" + getScriptString() + "</script>";
73
73
  String html = this.readAssetStream(responseStream);
74
+
75
+ // Insert the js string at the position after <head> or before </head> using StringBuilder
76
+ StringBuilder modifiedHtml = new StringBuilder(html);
74
77
  if (html.contains("<head>")) {
75
- html = html.replaceFirst("<head>", "<head>\n" + js + "\n");
78
+ modifiedHtml.insert(html.indexOf("<head>") + "<head>".length(), "\n" + js + "\n");
79
+ html = modifiedHtml.toString();
76
80
  } else if (html.contains("</head>")) {
77
- html = html.replaceFirst("</head>", js + "\n" + "</head>");
81
+ modifiedHtml.insert(html.indexOf("</head>"), "\n" + js + "\n");
82
+ html = modifiedHtml.toString();
78
83
  } else {
79
84
  Logger.error("Unable to inject Capacitor, Plugins won't work");
80
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "5.7.1",
3
+ "version": "5.7.3",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",