Skip to content

Correct way to inject ad blocker in React Native WebView #3039

Open
@Alwinator

Description

@Alwinator

I am working on a react native app with a web view that should block ads. The web view offers a way to inject javascript code. What is the correct way to inject your ad blocker?

I tried around but found no solution. It could look similar to the code below:

<WebView
  source={{
    uri: 'https://website-with-ads.example.com',
  }}
  javaScriptEnabled={true}
  injectedJavaScript={`
    var my_script = document.createElement('script');
    my_script.setAttribute('src','https://cdn.jsdelivr.net/npm/@cliqz/adblocker-webextension/dist/adblocker.umd.min.js');
    document.head.appendChild(my_script);
`}
/>

Thanks for your support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions