Display name
Display name

Reputation: 2747

Control what JS is executed in an Android WebView

Is it possible to control which JS is executed in an Android WebView on a fine-grained level? As far as I can tell it is only possible to enable/disable JS in the WebView globally and add JS Interfaces.

But what about blocking just certain APIs in a WebView? Is this possible?

Upvotes: 1

Views: 129

Answers (1)

Mikhail Naganov
Mikhail Naganov

Reputation: 6881

This is what you can do:

  1. Prevent certain JS source files from being loaded by overriding WebViewClient.shouldInterceptRequest.

  2. After loading the page, override the functions / object you want to disable with empty functions / nulls / whatever.

Upvotes: 2

Related Questions