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

V6.1.5 [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method injectJavascriptFileFromUrl on channel com.pichillilorenzo/flutter_inappwebview_2104612796416) #2506

Open
1 of 2 tasks
Liruochen1207 opened this issue Jan 18, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Liruochen1207
Copy link

Liruochen1207 commented Jan 18, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hi, I am building a multi person synchronized movie app. When I want to listen on a video playing or click event, it returns "null".
For example: XPATH element /html/body/div/div/video in https://www.yinghua3.com/index.php/vod/play/id/11852/sid/4/nid/1.html/
it can't be play by automatic so, I try to inject JQuery to control video playing. But unfortunately,it throwed an error..

I followed the guide but it doesn't work
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method injectJavascriptFileFromUrl on channel com.pichillilorenzo/flutter_inappwebview_2104612796416)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)

#1 WindowsInAppWebViewController.injectJavascriptFileFromUrl (package:flutter_inappwebview_windows/src/in_app_webview/in_app_webview_controller.dart:1968:5)

#2 WebViewGenerator.setWebView. (package:flake/generator/webview.dart:74:9)

Expected Behavior

I can't found same question in other issues. May be change an other version?

Steps with code example to reproduce

Steps with code example to reproduce
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

import '../contact/ws.dart';
import 'base_generator.dart';

class WebViewGenerator extends GeneratorBase {
  late String _url;
  String default_url = "https://www.yinghua3.com/index.php/vod/play/id/11852/sid/4/nid/1.html/"; // A Anime website
  // String default_url = "http://localhost:5000/";
  // String default_url = "https://cn.bing.com/";
  // String default_url = "https://www.baidu.com//";
  WebViewEnvironment? webViewEnvironment;
  InAppWebViewController? webViewController;
  late int _hash;

  int scrollingTimeOut = 0;


  WebViewGenerator(super.background) {
    _url = default_url;
    _hash = hashCode;
    initWebView();
    initWsChannel();
    setWebView();

  }

  WebViewGenerator.fromHash(super.background, int hash, String url) {
    _url = url;
    _hash = hash;
    initWebView();
    initWsChannel();
    setWebView();

  }

  void createSignal() {
    background.ws.createWebview(_hash, default_url, 0, 0);
  }

  void setWebView() {
    setBackGroundColor(Colors.white);
    setChild(InAppWebView(
      webViewEnvironment: webViewEnvironment,
      initialUrlRequest: URLRequest(url: WebUri(_url)),
      initialSettings: InAppWebViewSettings(
        resourceCustomSchemes: ["my-special-custom-scheme"],
        allowsLinkPreview: false,
        allowBackgroundAudioPlaying: true,
      ),
        onConsoleMessage:(controller, log){
          parseConsoleLogMsg(log);
        },
      onLoadStart: (controller, url) {
        webViewController = controller;
        if (url.toString() != _url) {
          background.ws.jumpWebview(_hash, url.toString());
          print("need change");

        }
        listenOnJsEvents(_hash);
      },
      onLoadStop: (controller, webUri) async {
        await controller.injectJavascriptFileFromUrl(
            urlFile: WebUri('https://code.jquery.com/jquery-3.3.1.min.js'),
            scriptHtmlTagAttributes: ScriptHtmlTagAttributes(id: 'jquery', onLoad: () {
              print("jQuery loaded and ready to be used!");
            }, onError: () {
              print("jQuery not available! Some error occurred.");
            }));
      },
      onWebViewCreated: (controller) {
        webViewController = controller;
      },
    ));
  }

  Future<void> setUrl(String s) async {
    // print(s);
    String currentUrl = (await webViewController?.getUrl()).toString();
    // print(currentUrl);
    // if (currentUrl == "about:blank") {
    //   print("jump");
    //   webViewController?.loadUrl(urlRequest: URLRequest(url: WebUri(s)));
    //   return;
    // }
    if (currentUrl == s) {
      return;
    }
    if (_url != s) {
      // listenOnJsClick();
      print("jump");
      webViewController?.loadUrl(urlRequest: URLRequest(url: WebUri(s)));
      _url = s;
    }
  }

  void scrollTo({required double x, required double y}) {
    String jsCode = """
    window.scrollTo($x, $y);
    """;

    if (scrollingTimeOut <= 0) {
      webViewController?.evaluateJavascript(source: jsCode);
    }
    if (scrollingTimeOut <= -1000000) {
      scrollingTimeOut = 1;
    }


  }
  
  void parseConsoleLogMsg(ConsoleMessage log){
    var result = jsonDecode(log.message);
    print("LOGGER");
    print(log);
    result = jsonDecode(result);
    int hashId = result['hash'];
    String eventType = result['type'];

    if (hashId == _hash) {
      switch (eventType) {
        case "click":
          print("CLICKED");
          var clickX = result['x'];
          var clickY = result['y'];
          background.ws.clickWebview(_hash, clickX, clickY);
          // var info = result['info'];
          // print(info);
          // print(info.runtimeType);

          break;

        case "scroll":
          print("SCROLLED");
          double scrollX = result['scrollX'] + 0.0;
          double scrollY = result['scrollY'] + 0.0;
          print(scrollY);
          if (scrollingTimeOut > 0) {
            background.ws.scrollWebview(_hash, scrollX, scrollY);
            background.ws.checkRefresh();
          }


          break;

        default:
          print("other type");
      }
    }
  }
  
  void listenOnJsEvents(int hash) {
    String jsCode = """

    window.addEventListener('scroll', () => {
      console.log(JSON.stringify({
        'hash': $hash,
        'type': 'scroll',
        'scrollX': window.scrollX || document.documentElement.scrollTop,
        'scrollY': window.scrollY || document.documentElement.scrollTop,
      }));
      
    });


    window.addEventListener('click', function(event) {

      var elementInfo = {
        'tagName': event.target.tagName,
        'id': event.target.id,
        'className': event.target.className,
        'innerText': event.target.innerText
      };

      console.log(JSON.stringify({
        'hash': $hash,
        'type': 'click',
        'x' : event.clientX,
        'y' : event.clientY,
        'info': elementInfo,
      }));

    });

  """;

    webViewController?.evaluateJavascript(source: jsCode);

  }
  
  
  int getViewHash() {
    return _hash;
  }

  Future<void> initWsChannel() async {
    background.hashOfWebView.add(_hash);
  }

  Future<void> initWebView() async {
    if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
      final availableVersion = await WebViewEnvironment.getAvailableVersion();
      assert(availableVersion != null,
          'Failed to find an installed WebView2 Runtime or non-stable Microsoft Edge installation.');

      webViewEnvironment = await WebViewEnvironment.create(
          settings: WebViewEnvironmentSettings(
              userDataFolder: 'YOUR_CUSTOM_PATH',
              customSchemeRegistrations: [
            CustomSchemeRegistration(
                scheme: "my-special-custom-scheme",
                allowedOrigins: ['*'],
                treatAsSecure: true,
                hasAuthorityComponent: true)
          ]));
    }
  }

  @override
  void refreshGenerator() {}

  TextStyle getTextStyle() {
    return TextStyle(color: Colors.black, fontSize: getFontSize());
  }
}

Stacktrace/Logs

Stacktrace/Logs
Performing hot restart...
Syncing files to device Windows...
Restarted application in 655ms.

======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 197 pixels on the bottom.

The relevant error-causing widget was: 
  Column Column:file:///D:/IdeaProjects/flake/lib/generator/base_generator.dart:211:14
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#c3b5c relayoutBoundary=up3 OVERFLOWING
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=1265.3, 0.0<=h<=682.7)
...  size: Size(1265.3, 682.7)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================
[WindowsInAppWebViewWidget] (windows) WindowsInAppWebViewWidget ID 2106550086272 calling "onWebViewCreated" using []
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onLoadStart" using {url: https://www.yinghua3.com/}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onProgressChanged" using {progress: 0}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onLoadStart" using {url: https://www.yinghua3.com/}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onProgressChanged" using {progress: 0}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onProgressChanged" using {progress: 33}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onUpdateVisitedHistory" using {isReload: false, url: https://www.yinghua3.com/}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onTitleChanged" using {title: 樱花动漫-专注动漫的网站-免费在线观看动漫樱花}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onProgressChanged" using {progress: 66}
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onProgressChanged" using {progress: 100}
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method injectJavascriptFileFromUrl on channel com.pichillilorenzo/flutter_inappwebview_2106550086272)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
<asynchronous suspension>
[WindowsInAppWebViewController] (windows) WebView ID 2106550086272 calling "onLoadStop" using {url: https://www.yinghua3.com/}
#1      WindowsInAppWebViewController.injectJavascriptFileFromUrl (package:flutter_inappwebview_windows/src/in_app_webview/in_app_webview_controller.dart:1968:5)
<asynchronous suspension>
#2      WebViewGenerator.setWebView.<anonymous closure> (package:flake/generator/webview.dart:70:9)
<asynchronous suspension>

Flutter version

Flutter (Channel stable, 3.24.3, on Microsoft Windows [版本 10.0.19045.5371], locale zh-CN)

Operating System, Device-specific and/or Tool

I am building windows app

Operating System Name: Microsoft Windows 10 Home Chinese Version
Version 1.0.19045 Internal Version 19045
There is no information available for other operating system descriptions
Operating system manufacturer Microsoft Corporation
System name DESKTOP-1A58POQ
System manufacturer MECHREVO
System model Taitan Series GM7MG7M
System type based on x64 computer
System SKU 0001
Processor Intel (R) Core (TM) i7-10875H CPU @ 2.30GHz, 2304 MHz, 8 cores, 16 logical processors
BIOS version/date American Megatrends Inc. N.1.09MRO06, 2021/3/16
SMBIOS version 3.2
Embedded controller version 1.18
BIOS Mode UEFI
Motherboard manufacturer MECHREVO
Motherboard product GM7MG7M
Motherboard version Standard
Platform role movement
Safe boot status enabled
PCR7 configuration needs to be improved to view
Windows directory C: \ WINDOWS
System directory C: \ WINDOWS \ system32
Start device \ Device \ HarddiskVolume2
Regional Setting in China
Hardware Abstraction Layer Version="1.0.19041.5072"
Username DESKTOP-1A58POQ \ Streamer
Time Zone: China Standard Time
Installed physical memory (RAM) 32.0 GB
Total physical memory 31.9 GB
Available physical memory 15.2 GB
Total virtual memory 36.4 GB
Available virtual memory 13.0 GB
Page file space 4.50 GB
Page file C: \ pagefile.sys
Enable kernel DMA protection
Virtualization based security is running
Security attributes based on virtualization security requirements
Basic virtualization support for security attributes provided by virtualization based security, secure boot, DMA protection, UEFI code is read-only, SMM Security Mitigations 1.0, Pattern based execution control, APIC virtualization
Virtualization based security services have been configured
Virtualization based security services are running
Device encryption support needs to be improved to view
The virtual machine monitoring program has been detected. Will not display the required features for Hyper-V.

Plugin version

v6.1.5

Additional information

No response

Self grab

  • I'm ready to work on this issue!
@Liruochen1207 Liruochen1207 added the bug Something isn't working label Jan 18, 2025
@Liruochen1207 Liruochen1207 changed the title [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method injectJavascriptFileFromUrl on channel com.pichillilorenzo/flutter_inappwebview_2104612796416) V6.1.5 [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method injectJavascriptFileFromUrl on channel com.pichillilorenzo/flutter_inappwebview_2104612796416) Jan 18, 2025
@laishere
Copy link

This method is not implemented on windows platform.
You can try to inject the <script> tag yourself with evaluateJavascript.

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

2 participants