Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluateJavascript doesn't work in Web platform #2412

Open
1 of 2 tasks
xOldeVx opened this issue Nov 12, 2024 · 1 comment
Open
1 of 2 tasks

evaluateJavascript doesn't work in Web platform #2412

xOldeVx opened this issue Nov 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@xOldeVx
Copy link

xOldeVx commented Nov 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

evaluateJavascript do nothing

Expected Behavior

evaluateJavascript will perform the script

Steps with code example to reproduce

evaluateJavascript doesn't work in Web platform, in other platforms it's working well

Steps with code example to reproduce
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class HelloWidget extends StatefulWidget {
  const HelloWidget({super.key});

  @override
  State<HelloWidget> createState() => _HelloWidgetState();
}

class _HelloWidgetState extends State<HelloWidget> {
  late InAppWebViewController webViewController;

  final htmlHello = """
  <!DOCTYPE html>
  <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <p4>Hello</p4>
    </body>
</html>
  """;
  InAppWebViewSettings settings = InAppWebViewSettings(
    mediaPlaybackRequiresUserGesture: false,
    clearCache: true,
    javaScriptEnabled: true,
  );

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 300,
      width: 300,
      color: Colors.white,
      child: InAppWebView(
          initialData: InAppWebViewInitialData(data: htmlHello),
          initialSettings: settings,
          onWebViewCreated: onWebViewCreated,
          onLoadStop: (controller, url) async {
            webViewController.evaluateJavascript(source: "alert('Loaded')"); // Do nothing instead of pop an Alert message

            var result = await webViewController.evaluateJavascript(source: "1 + 1");
            print(result.runtimeType); // return null instead of int
            print(result); // return null instead of 2

            result =
                await webViewController.evaluateJavascript(source: "new XMLSerializer().serializeToString(document);");
            print(result.runtimeType); // return null instead of String
            print(result); // return null instead of whole web page HTML String
          }),
    );
  }

  void onWebViewCreated(InAppWebViewController controller) {
    webViewController = controller;
  }
}

Stacktrace/Logs

Stacktrace/Logs
No logs

Flutter version

v3.24.4

Operating System, Device-specific and/or Tool

Chrome Version 120.0.6099.109 (Official Build) (arm64)

Plugin version

v6.1.5

Additional information

No response

Self grab

  • I'm ready to work on this issue!
@xOldeVx xOldeVx added the bug Something isn't working label Nov 12, 2024
@xOldeVx
Copy link
Author

xOldeVx commented Nov 17, 2024

As you can see in the code above, I'm using the official in_app_webview examples and it doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant