Creating a Custom Browser: Prevent External Links from Opening in Default Browser

Good morning everyone,

am trying to create a browser and I am starting with a simple custom WebView. I can reach the homepage, but some websites, as soon as you connect to their address, automatically open the default browser of the smartphone via JavaScript and launch the “intent” link directly in the main browser. I would like my browser to function entirely like a regular browser, so I want any kind link to open in my browser that I am creating in Kodular, rather than in my Chrome browser.

Here is my current code:

Let me give you a practical example to explain myself better:

  • I open my browser app with the homepage “google.com,” for example.
  • I search for a website using a keyword on Google.
  • I click the hyperlink from the search results on Google (for example) for the website, and I am redirected to the homepage of the site.
  • The site, immediately after loading its homepage, uses JavaScript to automatically open my Chrome browser, where it displays ads, via an intent. In this specific case, it is done like this: “intent://intentlink#Intent;scheme=https;package=com.android.chrome;end.”
  • I have to close my Chrome browser and reopen the browser that I am creating in Kodular.

What I would like to do instead:

  • I open my browser app with the homepage “google.com,” for example.
  • I search for a website using a keyword on Google.
  • I click the hyperlink from the search results on Google (for example) for the website, and I am redirected to the homepage of the site.
  • After the site has loaded its homepage, it automatically opens the page NOT in my Chrome browser but in a tab of my browser, where it can display all the ads it wants through an intent. In this specific case, it is done like this: “intent://intentlink#Intent;scheme=https;package=com.android.chrome;end.”
  • I do not need to go through a double step because the ads open directly in my browser, and I can use my browser to navigate without an external app being launched to load the deep links.

Why can’t I achieve this goal with my code?

The intents that the javascript of some website have are all hyperlinks that open my default browser and not other apps.

Thank you in advance for your help.

Try the custom webview extension.

I am using custom webview yet. See my image. Thank you anyway for your answer.