You only have the power to close a tab if you were the one that opened that tab.
In the following example the close
button will only work after opening a new tab using the link.
export class MyComponent {
close() {
window.close();
}
}
<a href="http://localhost:4200" target="blank">Open New Tab</a><br />
<button (click)="close()">close</button>
From this article: https://www.thesitewizard.com/javascripts/close-browser-tab-or-window.shtml
On all modern browsers, the web page to be closed must be the first in that window/tab's session history.
And further:
Modern browsers will also resist your attempt to trick them into thinking that an existing window/tab was opened with JavaScript when it was not.
This is done to protect the user's session history.