Search code examples
javascriptgoogle-chromepopupchrome-extension-manifest-v3chrome-extension-manifest-v2

Chrome Extension Question: How to open popup_1.html if a statement is true, else open popup_2.html if a statement is false?


I'm new in developing Chrome Extensions and a beginner in JavaScript. I need help in my chrome extension project.

Either if/else or a switch statement would be okay. I can't find a solution so far. I need my popup to show popup_1.html if the condition is true, and if it is false, then use popup_2.html


Solution

  • First, Set html file by setPopup method
    then open popup by openPopup(); method

    const condition = true;
    chrome.action.setPopup({ popup:condition ?  "popup_1.html": "popup_2.html"  });
    chrome.action.openPopup();