How to add preloader when inAppBrowser loads pages?

I need a preloader to display during page load in inAppBrowser, I tried to add it using html, css, js and methods browser.executeScript(...), browser.insertCSS(...), the preloader appeared, but after it there was a white screen, also tried to do it with using cordova-plugin-native-spinner and cordova-plugin-dialogs, but in both cases a white screen also appeared.
For example, I did it like this:

import { Component } from "@angular/core";
import { Platform } from "ionic-angular";
import { InAppBrowser } from "@ionic-native/in-app-browser";
import { SpinnerDialog } from '@ionic-native/spinner-dialog/ngx';

@Component({
  template: "<p>....loading</p>"
})
export class HomePage {
  constructor(
    private iab: InAppBrowser,
    public platform: Platform,
    private spinnerDialog: SpinnerDialog) {
    platform.ready().then(() => {
      let browser = this.iab.create("https://www.google.com", "_blank", {
        location: 'no',
        clearcache: 'yes',
        clearsessioncache: 'yes'
      });

      browser.show();

      browser.on('loadstart').subscribe(() => {
        this.spinnerDialog.show();     
      }, err => {
        this.spinnerDialog.hide();
      })

      browser.on('loadstop').subscribe(()=>{
        this.spinnerDialog.hide();
      }, err =>{
        this.spinnerDialog.hide();
      })
    });
  }
}

Or so:

import { Component } from "@angular/core";
import { Platform } from "ionic-angular";
import { InAppBrowser } from "@ionic-native/in-app-browser";

@Component({
  template: "<p>....loading</p>"
})
export class HomePage {
  constructor(private iab: InAppBrowser, public platform: Platform) {
    platform.ready().then(() => {
      let browser = this.iab.create("https://www.google.com", "_blank", {
        zoom: "no",
        location: "no"
      });

      browser.show();

      browser.on("loadstart").subscribe( () => {
        browser.executeScript({
          code:
            `document.body.innerHTML = "<div class='preloader'>
              <div class='preloader__row'>
                <div class='preloader__item'></div>
                <div class='preloader__item'></div>
              </div>
            </div>"`
        });
        browser.insertCSS({
          code: `.preloader {
          position: fixed;
          left: 0;
          top: 0;
          right: 0;
          bottom: 0;
          background: #e0e0e0;
          z-index: 1001;
        }

        .preloader__row {
          position: relative;
          top: 50%;
          left: 50%;
          width: 70px;
          height: 70px;
          margin-top: -35px;
          margin-left: -35px;
          text-align: center;
          animation: preloader-rotate 2s infinite linear;
        }

        .preloader__item {
          position: absolute;
          display: inline-block;
          top: 0;
          background-color: #337ab7;
          border-radius: 100%;
          width: 35px;
          height: 35px;
          animation: preloader-bounce 2s infinite ease-in-out;
        }

        .preloader__item:last-child {
          top: auto;
          bottom: 0;
          animation-delay: -1s;
        }

        @keyframes preloader-rotate {
          100% {
            transform: rotate(360deg);
          }
        }

        @keyframes preloader-bounce {
          0%,
          100% {
            transform: scale(0);
          }

          50% {
            transform: scale(1);
          }
        }

        .loaded_hiding .preloader {
          transition: 0.3s opacity;
          opacity: 0;
        }

        .loaded .preloader {
          display: none;
        }`
        });
        browser.executeScript({
          code: `window.onload = function () {
            document.body.classList.add('loaded_hiding')
            window.setTimeout(function () {
              document.body.classList.add('loaded')
              document.body.classList.remove('loaded_hiding')
            }, 500)
          }`
        });
      });
    });
  }
}

I am not good at Angular, Ionic and Cordova, if you need any more information about the project settings, I can provide.

Source: New feed
Source Url How to add preloader when inAppBrowser loads pages?