Google chrome extension 单击按钮时,打开从popup.html打开的同一窗口

Google chrome extension 单击按钮时,打开从popup.html打开的同一窗口,google-chrome-extension,Google Chrome Extension,我有一个chrome扩展名和一个popup.html,这个popup.html用户界面只有一个按钮,点击它就会在外部弹出窗口中打开一个网页 popup.html <body> <article style="width: 34rem"> <button id="open">Click to open the App</button> </article> <s

我有一个chrome扩展名和一个popup.html,这个popup.html用户界面只有一个按钮,点击它就会在外部弹出窗口中打开一个网页

popup.html

<body>
    <article style="width: 34rem">
        <button id="open">Click to open the App</button>
    </article>
<script src="popup.js"></script>
<body>
用户单击popup.html上的按钮,它会打开一个窗口,新窗口会聚焦(我对此没有问题),当新窗口不活动时,用户可以最小化它

假设用户最小化了新窗口并再次单击popup.html上的按钮,则会创建新窗口的另一个实例


我正在寻找一种方法,以打开焦点相同的早期最小化窗口,而不是新的。我如何实现它?

希望这能解决您的问题

$(document).ready(function() {
    $("#open").click(function() {
        chrome.tabs.query({
            title: 'Your title name'
        }, tabs => {
            if (!tabs.length) {
                window.open("https://www.example.com", 'Your title name', 'height=678,width=650').focus();
                return;
            }
            chrome.windows.update(tabs[0].windowId, {
                focused: true
            });
            chrome.tabs.update(tabs[0].id, {
                active: true
            });
        });
    });
});
$(document).ready(function() {
    $("#open").click(function() {
        chrome.tabs.query({
            title: 'Your title name'
        }, tabs => {
            if (!tabs.length) {
                window.open("https://www.example.com", 'Your title name', 'height=678,width=650').focus();
                return;
            }
            chrome.windows.update(tabs[0].windowId, {
                focused: true
            });
            chrome.tabs.update(tabs[0].id, {
                active: true
            });
        });
    });
});