"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Chrome extension development: How open popup.html to the right and top of the page

Chrome extension development: How open popup.html to the right and top of the page

Published on 2024-11-08
Browse:909

Chrome extension development: How open popup.html to the right and top of the page

Buy default the popup opened below the extension icon, we can change the position by create a new window

chrome.action.onClicked.addListener(async (tab) => {
    openPopup(tab)
});

const openPopup = async (tab) => {
    const currentWindow = await chrome.windows.getCurrent();
    let window = await chrome.windows.create({
        url: './popup.html',
        type: 'popup',
        width: 320,
        height: 578,
        left: currentWindow.left   currentWindow.width - 320,
        top: 100
    });
    chrome.windows.update(window.id, { focused: true });
}
Release Statement This article is reproduced at: https://dev.to/ccsunnydev/chrome-extension-development-how-open-popuphtml-to-the-right-and-top-of-the-page-4dbc?1If there is any infringement, please Contact [email protected] to delete
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3