Login & Authentication in Chrome Extension Practice

前端 未结 1 1494
夕颜
夕颜 2021-01-19 02:37

I\'m working on a chrome extension and trying to implement an authentication method (firebase). I\'m confused by what has to go where, since the popup.html doesn\'t allow in

相关标签:
1条回答
  • 2021-01-19 03:19

    You could try to have the login/password input boxes in the popup but run the actual login code in the background page. You can do that sending a message from the popup to the background page or directly from the popup using something like:

    popup.html:

    <input type="text" id="email">
    <input type="password" id="password">
    

    popup.js:

    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;
    
    chrome.runtime.getBackgroundPage(function(bgPage){
        bgPage.performFirebaseLoginWithEmailAndPassword(email,password);
    });
    

    Since the background page is always on, the login state should be preserved when the popup is closed.

    0 讨论(0)
提交回复
热议问题