'use strict';

const log = require('intel').getLogger('browsertime.video');

module.exports = async function(driver) {
  log.debug('Add orange color');
  // We tried other ways for Android (access an orange page)
  // That works fine ... but break scripts
  // https://github.com/sitespeedio/browsertime/issues/802
  const orangeScript = `
      (function() {
        const orange = document.createElement('div');
        orange.id = 'browsertime-orange';
        orange.style.position = 'absolute';
        orange.style.top = '0';
        orange.style.left = '0';
        orange.style.width = Math.max(document.documentElement.clientWidth, document.body.clientWidth) + 'px';
        orange.style.height = Math.max(document.documentElement.clientHeight,document.body.clientHeight) + 'px';
        orange.style.backgroundColor = '#DE640D';
        orange.style.zIndex = '2147483647';
        document.body.appendChild(orange);
        document.body.style.display = '';
      })();`;
  return driver.executeScript(orangeScript);
};

@@ -69,16 +69,68 @@
 ideo');%0A
+const %7B until, By %7D = require('selenium-webdriver');
 %0Amodule.
@@ -1031,16 +1031,16 @@
 ;%60;%0A
+%0A
   
-return
+await
  dri
@@ -1072,11 +1072,218 @@
 cript);%0A
+  // It seems that in some cases the video do not have any orange at the start, so make sure we%0A  // the div orange div really exits%0A  return driver.wait(until.elementsLocated(By.id('browsertime-orange')));%0A
 %7D;%0A

Verify that the orange div exists before moving on (#1076)