My Chrome extension's popup opens a new window via window.open(), when I am clicking on button (Sign In) present in popup screen for authentication, after authentication done that child window closed, but it closes the extension's popup itself. Here extension popup disappears quickly before the user notices the message after authentication done.
This is how the window is opened
window.open(url, target, windowFeatures)
Is this because of the focus shifting between windows? What can I do for popup window to stay on while longer so the user notices the message ?
CodePudding user response:
Create a new tab with popup and it will create a window for authentication.
popup.html
<html>
<body>
<script src="popup.js"></script>
</body>
</html>
popup.js
chrome.tabs.create({ url: "auth.html" });
auth.html
<html>
<body>
<button id="auth">auth</button>
<script src="auth.js"></script>
</body>
</html>
auth.js
document.getElementById("auth").onclick = () => {
auth();
}
CodePudding user response:
When you run this code in the popup, it opens a new tab in the background and keeps the popup open:
chrome.tabs.create({ active: false, url: "https://stackoverflow.com/" });
When you close the new tab by calling chrome.tabs.remove in the popup, the popup also stays open.
There is also chrome.windows.create, but it always closes the popup, even when you call it with focused: false
and/or state: "minimized"
Tested in Chromium 108.0.5359.124 (Official Build) Arch Linux (64-Bit))