src/service/standard-actions-impl.js
/**
   * Handles the `handleCloseOrNavigateTo_` action.
   * This action tries to close the requesting window if allowed, otherwise
   * navigates the window.
   *
   * Window can be closed only from top-level documents that have an opener.
   * Without an opener or if embedded, it will deny the close method.
   * @param {!./action-impl.ActionInvocation} invocation
   * @return {!Promise}
   * @private Visible to tests only.
   */
Handles the `handleCloseOrNavigateTo_` action.
This action tries to close the requesting window if allowed, otherwise
navigates the window.

Window can be closed only from top-level documents that have an opener.
Without an opener or if embedded, it will deny the close method.
@param {!./action-impl.ActionInvocation} invocation
@return {!Promise}
@private Visible to tests only.
Handles the ` handleCloseOrNavigateTo_ ` action . This action tries to close the requesting window if allowed otherwise navigates the window . Window can be closed only from top - level documents that have an opener . Without an opener or if embedded it will deny the close method . @param { ! . / action - impl . ActionInvocation } invocation @return { !Promise } @private Visible to tests only .
handleCloseOrNavigateTo_(invocation) {
    const {node} = invocation;
    const win = (node.ownerDocument || node).defaultView;
    const hasParent = win.parent != win;
    const canBeClosed = win.opener && this.ampdoc.isSingleDoc() && !hasParent;
    let wasClosed = false;
    if (canBeClosed) {
      win.close();
      wasClosed = win.closed;
    }
    if (!wasClosed) {
      return this.handleNavigateTo_(invocation);
    }
    return Promise.resolve();
  }
handleCloseOrNavigateTo_ ( invocation ) { const { node } = invocation ; const win = ( node . ownerDocument || node ) . defaultView ; const hasParent = win . parent != win ; const canBeClosed = win . opener && this . ampdoc . isSingleDoc ( ) && ! hasParent ; let wasClosed = false ; if ( canBeClosed ) { win . close ( ) ; wasClosed = win . closed ; } if ( ! wasClosed ) { return this . handleNavigateTo_ ( invocation ) ; } return Promise . resolve ( ) ; }
Handles the `handleCloseOrNavigateTo_` action.
Handles the ` handleCloseOrNavigateTo_ ` action .
// Don't allow closing if embedded in iframe or does not have an opener or // embedded in a multi-doc shadowDOM case. // Note that browser denies win.close in some of these cases already anyway, // so not every check here is strictly needed but works as a short-circuit. // Browser may still deny win.close() call, that would be reflected // synchronously in win.closed