Accessing public methods of Android WebView
See original GitHub issueTell us about the problem
I am trying to use the public method setWebContentsDebuggingEnabled()
of the Android WebView class, but I’m not sure how to access it. I tried
webView.android.setWebContentsDebuggingEnabled(true);
but it doesn’t work as I get the following error:
webView.android.setWebContentsDebuggingEnabled is not a function
See below for details.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
- CLI: 3.1.3
- Cross-platform modules: 3.1.1
- Runtime(s): tns-android 3.1.1
- Plugin(s): “nativescript-angular”: “4.2.0”, “nativescript-localstorage”: “1.1.2” “nativescript-theme-core”: “1.0.4” “nativescript-css-loader”: “0.26.1” “nativescript-dev-android-snapshot”: “0.0.9” “nativescript-dev-sass”: “1.3.0” “nativescript-dev-webpack”: “0.6.0”
Note: Project based on the seed angular-seed-advanced
Please tell us how to recreate the issue in as much detail as possible.
Here’s the ngAfterViewInit
method where I setup the WebView:
ngAfterViewInit() {
let webView: WebView = this.webViewRef.nativeElement;
webView.on(WebView.loadStartedEvent, function() {
webView.android.getSettings().setBuiltInZoomControls(true);
webView.android.getSettings().setDisplayZoomControls(false);
webView.android.setWebContentsDebuggingEnabled(true);
});
webView.on(WebView.loadFinishedEvent, function (args: LoadEventData) {
let message;
if (!args.error) {
message = 'WebView finished loading of ' + args.url;
} else {
message = 'Error loading ' + args.url + ': ' + args.error;
}
console.log('WebView message - ' + message);
});
}
If I remove the line with setWebContentsDebuggingEnabled
, the webview works.
The two methods calls in getSettings()
are working well because they are public methods of the Android WebSettings class, which is not the case of setWebContentsDebuggingEnabled()
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
WebView - Android Developers
Public constructors. WebView; WebView; WebView; WebView; WebView. Public methods. addJavascriptInterface; autofill; canGoBack; canGoBackOrForward ...
Read more >Access to WebView from another function in MainActivity class
You're trying to use view before it has been initialized. You need to wait until after view = (WebView) findViewById(R.id.
Read more >Android WebView Example Tutorial - DigitalOcean
For HTML code that is limited in terms of scope, we can implement the static method fromHtml() that belongs to the HTML Utility...
Read more >How to Use WebView in Android? - GeeksforGeeks
WebView is a view that displays web pages inside the application. It is used to turn the application into a web application. public...
Read more >Android - WebView - Tutorialspoint
WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @nmongiya for your help. Your code didn’t exactly work for me, but it was almost there. I did the following:
The initial code @davidsandoz posted didn’t work because the interface doesn’t have that property so TS won’t compile. Guess I’ll be sending a PR to update the interface.
A million thanks!
I still cannot tell why
webView.android.setWebContentsDebuggingEnabled(true);
is not working, but I eventually figured out thatandroid.webkit.WebView.setWebContentsDebuggingEnabled(true);
does the job.