cordova-plugin-splashscreen icon indicating copy to clipboard operation
cordova-plugin-splashscreen copied to clipboard

Rendering to fast?

Open ThorvaldAagaard opened this issue 6 years ago • 1 comments

Bug Report

It looks like the code is executed to fast, when running in a browser, so when the show-function is called, then document.body is still null, thus giving a javascript error

Problem

No splashscreen

What is expected to happen?

Splashscreen should be shown in browser

What does actually happen?

document.body.appendChild(localSplash); returns exception as document.body is still null

Information

Just waiting 200 ms before appending the splashscreen, like this

        window.setTimeout(function () {
            if (document.body) {
                document.body.appendChild(localSplash);
            }
        }, 200);

seems to fix the problem

Another idea might also be to make the hide more robust by adding a check before removing the child like this

        window.setTimeout(function () {
            console.log("Removing splash: " + innerLocalSplash);
            if (innerLocalSplash && innerLocalSplash.parentNode == document.body) {
                document.body.removeChild(innerLocalSplash);
            }
            innerLocalSplash = null;
        }, 1000);

Command or Code

Requires a fast computer, and I have seen it on the latest version of Chrome

Environment, Platform, Device

Chrome

Version information

Using cordova-plugin-splashscreen 5.0.3

Checklist

  • [X] I searched for existing GitHub issues
  • [ ] I updated all Cordova tooling to most recent version
  • [ ] I included all the necessary information above

ThorvaldAagaard avatar Jul 05 '19 19:07 ThorvaldAagaard

Thanks for your help, I have the exact same problem and it looks your first fix works.

Also, I would recommend using innerLocalSplash.remove() instead of document.body.removeChild(innerLocalSplash); to deal with edge cases, e.g. usage in Chrome Extension that might create multiple bodies when you close and open it

piwel avatar May 20 '21 12:05 piwel