How to block ads on in-app-browser plugin? #444
Replies: 1 comment
-
The answer is going to depend on what kind of ad you're trying to block. For network-based ads In app browser doesn't have a JS api to intercept or block network requests. There is some level of intercept ability natively, so I think it might be possible if you fork the plugin, you should be able to use the webview APIs to intercept and block requests going to whatever domain you want to block. The Cordova access controls normally do this for the main webview but the in-app browser is intended to behave more like a standard web browser and because it doesn't have direct access to the Cordova API, so it doesn't restrict the webview since it can more safely load "untrusted" content. With that being said it would be unwise to attempt to load a third-party website into the main cordova webview. I'm not sure if there is any other way to block network based as. For statically embedded ads Depending on how you're loading your IAB, there is an executeScript API which can probably be utilized to find the DOM node and remove or alter it. For script-based Ads As in ads that are embedded/dynamically created via a script but not necessary pulled from the network, I think the only option is to disable JS, which looking at the docs, a configuration option doesn't appear to be exposed, so a fork might be needed today (and perhaps a PR would be welcome for this feature). This will of course will prevent any JS from running in that webview and thus could break the website in other ways. I have no idea if any of these will actually work, I kinda just thought them up on the fly. |
Beta Was this translation helpful? Give feedback.
-
Howdy!
I'm looking for some way to block on networking level (or any other) certain ads from some websites on my ionic app. Is it possible?
Beta Was this translation helpful? Give feedback.
All reactions