-
Notifications
You must be signed in to change notification settings - Fork 95
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
WKWebView.loadPlugin() does not add plugin to 'window' in the webView's JS environment. #72
Comments
|
It should be |
Thank you for your quick response! I've tried several things, on your advice:
... but the error result is still exactly the same as written above. |
I see. I'll try rewriting my |
You can use safari attach the webview to check whether the user scripts generated by XWebView is injected into page. Please paste here if you find them. I can't find the root cause by eyes. You need to minimize the code of the test case to demonstrate the problem. If you can share a buildable project, I will try to debug it. |
Just finished some further investigation. Looks like I was wrong about there being no 'Tokenising' or 'HelloWorld' object on the window (I simply didn't see it - my bad), but the function names were not what I'd expected, and that was causing the error.
The problem is that no external name had been set for the 'text' parameter of the This is easily fixed by making the external parameter name anonymous (just adding an underscore before the parameter's internal name):
This way, the function is accessible in JS, as expected, as Perhaps the naming convention for functions has changed since the 2015 Quick Start guide? Or has this always been the case, but Swift's behaviour has changed..? In any case, it may be worth updating this part of the Quick Start guide. Thank you very much for your quick help. I'll investigate how to return a value from the method by referring to #52 . If I have any problems with that part, I'll add a reply under that issue page. This current issue can be closed. |
The guide was quite old. The problem caused by the swift change SE-0046. BTW, I keep updating the sample app with the library. |
I am trying to call a Swift function (which returns a String array) from the JavaScript environment of my webView.
I have copied your quick start instructions and tried your sample app. I am receiving no compile-time errors, yet when I run webView.evaluateJavascript(), no reference to my plugins are ever found.
Here is my ViewController.swift:
Upon webView finishing navigation, I'd like to call my native function
Tokenising.romaniseobj()
. However, despite loading both classes in as plugins, neither 'Tokenising' nor 'HelloWorld' appear on the webView's JS environment's window. WhenwebView.evaluateJavascript("window.HelloWorld.show();")
is called, I receive the following error message:When I print out every property on 'window', I find that indeed, there is no 'HelloWorld' property. This same error message occurs for calling
Tokenising.romaniseobj()
. What am I doing wrong?The text was updated successfully, but these errors were encountered: