capacitor-sso-webview 0.0.6 → 0.0.7

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.
@@ -25,6 +25,7 @@ public class SSOWebView {
25
25
  private Dialog dialog;
26
26
  private WebView webView;
27
27
  private boolean alreadyRedirected = false;
28
+ private boolean bodyRead = false;
28
29
 
29
30
  public void open(
30
31
  final Activity activity,
@@ -34,6 +35,7 @@ public class SSOWebView {
34
35
  final String title,
35
36
  final Listener listener) {
36
37
  alreadyRedirected = false;
38
+ bodyRead = false;
37
39
 
38
40
  dialog = new Dialog(activity, android.R.style.Theme_Light_NoTitleBar_Fullscreen);
39
41
 
@@ -111,65 +113,69 @@ public class SSOWebView {
111
113
 
112
114
  @Override
113
115
  public void onPageFinished(WebView view, String pageUrl) {
114
- super.onPageFinished(view, pageUrl);
115
-
116
- Uri u = Uri.parse(pageUrl);
117
- String host = u.getHost();
118
- String path = u.getPath();
119
-
120
- boolean isRedirectPage = host != null && host.equalsIgnoreCase(redirectHost) &&
121
- path != null && path.toLowerCase()
122
- .contains(redirectPathContains.toLowerCase());
123
-
124
- if (!isRedirectPage)
125
- return;
126
-
127
- final String finalUrl = pageUrl;
128
- final String finalCode = u.getQueryParameter("code") != null ?
129
- u.getQueryParameter("code") :
130
- "";
131
- final String finalState = u.getQueryParameter("state") != null ?
132
- u.getQueryParameter("state") :
133
- "";
134
-
135
- /* Delay 150ms — beri waktu body JSON ter-render ke DOM */
136
- view.postDelayed(new Runnable() {
137
- @Override
138
- public void run() {
139
- if (webView == null) return;
140
- webView.evaluateJavascript(
141
- "(function(){" +
142
- " var t = document.body" +
143
- " ? (document.body.innerText || document.body.textContent || '')" +
144
- " : '';" +
145
- " return t.trim();" +
146
- "})()",
147
- value -> {
148
- String body = value;
149
- if (body != null) {
150
- if (body.startsWith("\"") && body.endsWith("\""))
151
- body = body.substring(1, body.length() - 1);
152
- body = body.replace("\\\"", "\"")
153
- .replace("\\n", "\n")
154
- .replace("\\r", "")
155
- .replace("\\/", "/");
156
- }
157
- final String finalBody = (body != null) ? body : "";
158
- android.util.Log.d("SSOWebView",
159
- "body len=" + finalBody.length() +
160
- " preview=" + finalBody.substring(
161
- 0, Math.min(120, finalBody.length())));
162
-
163
- /* FIX: gunakan outer class reference */
164
- activity.runOnUiThread(() -> SSOWebView.this.dismiss());
165
-
166
- if (listener != null)
167
- listener.onRedirectIntercepted(
168
- finalUrl, finalCode, finalState, finalBody);
116
+ super.onPageFinished(view, pageUrl);
117
+
118
+ /* Guard: hanya proses sekali setelah redirect */
119
+ if (bodyRead) return;
120
+
121
+ Uri u = Uri.parse(pageUrl);
122
+ String host = u.getHost();
123
+ String path = u.getPath();
124
+
125
+ boolean isRedirectPage =
126
+ host != null && host.equalsIgnoreCase(redirectHost) &&
127
+ path != null && path.toLowerCase()
128
+ .contains(redirectPathContains.toLowerCase());
129
+
130
+ if (!isRedirectPage) return;
131
+
132
+ /* Set flag SEGERA — cegah double-fire */
133
+ bodyRead = true;
134
+
135
+ final String finalUrl = pageUrl;
136
+ final String finalCode = u.getQueryParameter("code") != null
137
+ ? u.getQueryParameter("code") : "";
138
+ final String finalState = u.getQueryParameter("state") != null
139
+ ? u.getQueryParameter("state") : "";
140
+
141
+ /* Delay 150ms beri waktu body JSON ter-render ke DOM */
142
+ view.postDelayed(new Runnable() {
143
+ @Override
144
+ public void run() {
145
+ if (webView == null) return;
146
+ webView.evaluateJavascript(
147
+ "(function(){" +
148
+ " var t = document.body" +
149
+ " ? (document.body.innerText || document.body.textContent || '')" +
150
+ " : '';" +
151
+ " return t.trim();" +
152
+ "})()",
153
+ value -> {
154
+ String body = value;
155
+ if (body != null) {
156
+ if (body.startsWith("\"") && body.endsWith("\""))
157
+ body = body.substring(1, body.length() - 1);
158
+ body = body.replace("\\\"", "\"")
159
+ .replace("\\n", "\n")
160
+ .replace("\\r", "")
161
+ .replace("\\/", "/");
162
+ }
163
+
164
+ final String finalBody = (body != null) ? body : "";
165
+ android.util.Log.d("SSOWebView",
166
+ "body len=" + finalBody.length() +
167
+ " preview=" + finalBody.substring(
168
+ 0, Math.min(120, finalBody.length())));
169
+
170
+ activity.runOnUiThread(() -> SSOWebView.this.dismiss());
171
+
172
+ if (listener != null)
173
+ listener.onRedirectIntercepted(
174
+ finalUrl, finalCode, finalState, finalBody);
175
+ }
176
+ );
169
177
  }
170
- );
171
- }
172
- }, 150);
178
+ }, 150);
173
179
  }
174
180
 
175
181
  private void dismiss() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-sso-webview",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "SSO WebView with URL intercept",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",