removeAllOverlays static method

dynamic removeAllOverlays(
  1. HtmlDocument htmlDoc, [
  2. bool allowRedirect = true
])

Removes any element that obscures another element from htmlDoc.

If there is an iFrame or object on the page, finds the largest one and:

  • if it is an iFrame referencing another page and source is available,
    • moves it inline
  • if it is an iFrame referencing another page and source is not available,
    • opens it in the current tab
  • if it is an Object or inline iFrame,
    • opens it in the current tab

then strip out everything ont the resulting page except:

Implementation

static removeAllOverlays(HtmlDocument htmlDoc, [bool allowRedirect = true]) {
  log.info('Function : removeAllOverlays, '
      'Parameters : {[htmlDoc,$htmlDoc], [allowRedirect,$allowRedirect]}');
  List pageElements = [];
  pageElements.addAll(htmlDoc.querySelectorAll('iframe'));
  pageElements.addAll(htmlDoc.querySelectorAll('object'));
  pageElements.sort(_compareElementArea);
  if (pageElements.isNotEmpty) {
    HtmlElement selected = pageElements.last;
    log.finest('Function : removeAllOverlays, selected : ${selected} '
        '(width ${selected.clientWidth}) (height ${selected.clientHeight})');
    if (selected.nodeName!.toLowerCase() == 'iframe') {
      new MyIFrame(htmlDoc, pageElements.last)
          .makeProminant(stripDownPage, allowRedirect);
    } else {
      stripDownPage(htmlDoc, selected);
    }
  } else {
    log.finest('Function : removeAllOverlays,  no iframe/object selected');
    stripDownPage(htmlDoc);
  }
  log.fine('Function : removeAllOverlays, Return : void');
}