Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

after use main branch code,run js on chrom still have a minor problem. #3

Closed
lhjandroid opened this issue Apr 9, 2021 · 3 comments
Closed

Comments

@lhjandroid
Copy link

code

class WebPageState extends State<WebPage> {

//   String js = '''
//   var remove=n=>{n.split(",").forEach(v=>{if(v.indexOf("@ID(")==0){document.getElementById(v.substring(4,v.length-1)).style.display="none"}else{for(let e of document.getElementsByClassName(v))e.style.display="none"}})}
// remove("ad top")
//   ''';

  String js = '''
  document.getElementsByClassName("ad top")
  ''';

  WebViewXController webviewController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: WebViewX(
        initialContent: 'https://online-video-cutter.com/cn/',
        initialSourceType: SourceType.URL_BYPASS,
        onWebViewCreated: (controller) {
          webviewController = controller;
          _evalRawJsInGlobalContext();
        },
        // jsContent: {
        //   EmbeddedJsContent(
        //     js: js,
        //   ),
        //   // EmbeddedJsContent(
        //   //   webJs:
        //   //   "function testPlatformSpecificMethod(msg) { TestDartCallback('Web callback says: ' + msg) }",
        //   //   mobileJs:
        //   //   "function testPlatformSpecificMethod(msg) { TestDartCallback.postMessage('Mobile callback says: ' + msg) }",
        //   // ),
        // },
      ),
    );
  }


  void _evalRawJsInGlobalContext() async {
    try {
      // webviewController.loadContent(
      //   'https://online-video-cutter.com/cn/',
      //   SourceType.URL,
      // );
      Future.delayed(Duration(seconds: 4),() async {
        var result = await webviewController.evalRawJavascript(js);
        print(result);
      });
    } catch (e) {
      print(e);
    }
  }

}

even if don't do any js shell,the console print

DOMException: Failed to set the 'href' property on 'Location': The current window does not have permission to navigate the target frame to 'about:srcdoc'.
    at HTMLDocument.<anonymous> (https://static.123apps.com/js/shared-v3.js?6eeaf:1:264239)
[object HTMLCollection]

and the web page is't show normal. such as this link https://online-video-cutter.com/cn.

@lhjandroid
Copy link
Author

image
the normal web page should be
image

@lhjandroid lhjandroid changed the title after use main branch code,run js on chrom still minor problem. after use main branch code,run js on chrom still have minor problem. Apr 9, 2021
@lhjandroid lhjandroid changed the title after use main branch code,run js on chrom still have minor problem. after use main branch code,run js on chrom still have a minor problem. Apr 9, 2021
@adrianflutur
Copy link
Owner

I'm afraid this has to do with the CORS proxies that this package uses (the html page that they return), so the problem is not really coming from the package itself.

This is as far as you can go unfortunately. You could try to fork the package and replace the public CORS proxies from src/utils/x-frame-options-bypass.dart (line 106-107) with your own CORS proxy server (you need to setup one yourself), to see if this solves the issue.
Or you could use the default SourceType.URL, but you won't be able to modify the html source.

Other than that, I don't think there is anything I can do.

@adrianflutur
Copy link
Owner

Closing this now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants