1

I have a Flutter app using flutter_inappwebview: ^6.1.0. The frontend is built in Flutter, and the backend is Spring Boot (Java).

In the Flutter app, I load a WebView using initialUrlRequest, pointing to a React-based webpage (form.tsx). The React page tries to dynamically load a JavaScript file via an API endpoint, then notifies Flutter when it's rendered.

React code(form.tsx)

const script: HTMLScriptElement = document.createElement('script');
script.src = formScriptUrl; // loaded via axios blob: "/down?formPath=/resources/example/form-ex.js"
script.defer = true;
script.onload = function () {
  window.flutter_inappwebview.callHandler('formRendered');
};
document.body.appendChild(script);

The JS file is fetched from a Spring API:

return await axios( {
  url: '/down?formPath=/resources/example/form-ex.js',
  method: 'GET',
  responseType: 'blob',
  headers: {
    'Content-Type': 'text/javascript'
    'Accept': 'application/json',
  },
});

Once the formRendered signal is received in Flutter, we run this:

await _webViewController?.evaluateJavascript(source: 'getBodyHtml()');

Where getBodyHtml() is:

const formEl = document.getElementById("body-html-area");
const BodyHtml = formEl?.innerHTML || '';
return BodyHtml;

Problem:

  1. No API call is made to /down?formPath=.... The server has no request or error logs.
  2. We wrapped the script logic in try-catch, with an alert() in case of errors — but no alert shows.
  3. The WebView just shows a blank screen.
  4. This issue occurs only for 2~3 users. Most users have no problems.
  • Devices include both Android and iOS.
  • Minimum Android version observed: 14
  • No consistent pattern (e.g., Galaxy S23 works for some, fails for others)

What I've tried:

  • Confirmed the JS file loads fine when accessed directly in browsers.
  • Confirmed window.flutter_inappwebview.callHandler() works for most users.
  • Verified getBodyHtml() works in normal conditions.
  • Confirmed correct MIME type (text/javascript) and response format (blob).
  • Added alert() statements in the script load path — but nothing is triggered for affected users.
  • No CORS error is shown (and most users work fine, so it shouldn't be a policy issue).

What could cause this script loading to silently fail on only a few devices?

Is there something about how blobs, script injection, or WebView caching works differently on a few devices or under rare network conditions?

1 Answer 1

0

Some WebView implementations (especially on newer Android/iOS versions) restrict loading scripts from blob URLs for security reasons.

If you fetch the JS as a blob and try to inject it as a <script src="blob:...">, it may silently fail on some devices.

Instead of using a blob URL, fetch the JS as text and inject it directly:

const response = await axios.get('/down?formPath=/resources/example/form-ex.js', { responseType: 'text' });

const script = document.createElement('script');

script.text = response.data;

document.body.appendChild(script);

Try disabling cache in your WebView:

InAppWebView(
  initialOptions: InAppWebViewGroupOptions(
    crossPlatform: InAppWebViewOptions(
      cacheEnabled: false,
      clearCache: true,
    ),
  ),
  // ...
)

Also, clear Service Worker caches in your React app if used.

Check your CSP and allow 'unsafe-inline' or 'unsafe-eval' for testing.

Sign up to request clarification or add additional context in comments.

1 Comment

But if it was received as a blob, that means the API call to /down?formPath=... was made. However, there are no request logs or error logs on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.