Is it possible to automatically close a tab in a browser if there’s history in it?

Right now I can automatically closed my tab after clicking on the save button and when there’s no history in the brower. But due business’s requirement, I need to perform that same behaviuor even if there’s history in the browser.
Is it possible?

I have this function

      window.close();
  };
    context: { clientName: GraphClientNames['XXXX'] },
      onCompleted: (data) => {
        showGenericMessage({
          id: uuid(),
          open: true,
          title: 'Success',
          icon: 'SUCCESS',
          message: 'Extended composition saved successfully',
        });
        setTimeout(() => {
          closeWindow();
        }, 2000);
      },
      onError: (error) => {
        showGenericMessage({
          id: uuid(),
          open: true,
          title: `Could not save extended composition`,
          icon: 'ERROR',
          message: String(error),
          closeMessageAfterTime: false,
        });
      },
    });

So after clicking on the save button, I wait 2 secs and the tab is closed automatically.
The question is how to perform the same but with history in the browser? thanks a lot