Search code examples
javascriptandroidiosflutterurl

Javascript loading blocked on URL click, unless forcefully refreshed


I am working on a Flutter mobile app that launches external URLs using the url_launcher package. One of the URLs I'm working with relies on JavaScript for tracking, but the JavaScript execution is blocked when the URL is initially loaded in an external browser. However, when users manually refresh the page, JavaScript is unblocked, and the URL returns a 200 status code. This behavior is consistent across desktop and mobile browsers.

My goal is to use this URL in my Flutter app and ensure that JavaScript is activated when the URL is launched in an external browser. I would like to programmatically trigger the refresh or reload action to achieve this.

Here is the current logic I'm using to launch the URL:

  final uri = Uri.parse('https://example.com');
        if (await canLaunchUrl(uri)) {
          launchUrl(uri, mode: LaunchMode.externalApplication);
        }

I have confirmed that JavaScript is enabled, and cookies are enabled in the external browser. The issue appears to be related to the initial page load. I also tested the URL by manually pasting it into a notepad and launching it in a Chrome browser, and the issue persisted until I tapped the reload icon.

Can anyone provide guidance on how to programmatically trigger the reload action for external URLs in a Flutter app to ensure that JavaScript is activated upon launch?


Solution

  • I didn't find a way to get this to work by using external browser via url_launcher package. I solved it by using in-app web view's reload functionality.