Problem with open PDF in InAppBrowser

Hello
I have a problem opening a PDF file in inAppBrowser. The mechanism for opening the file looks like this:

  1. I generate a PDF version of the report with a PHP script and save it to server.
  2. I check if the file is ready on the server, if it is, I open it in inAppBrowser, if not, I try again so I can be sure the file is there.

The opening function looks like this
window.open = cordova.InAppBrowser.open window.open(https://drive.google.com/viewerng/viewer?embedded=true&url=URL_TO_PDF, "_blank", "location=yes");

I use the “frame” from google to avoid downloading the file each time to the mobile device. I would like the user to be able to just see it in the browser. Sometimes the file is available immediately, sometimes I have to call the function several times which will reopen inAppBrowser and finally shows me PDF version. Has anyone encountered this problem?