DEV Community

ccsunny
ccsunny

Posted on

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 });
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)