window.location.replace returns 此站点无法提供安全连接,它发送了无效响应。 Vercel 部署和普通 JS

window.location.replace returns This site can’t provide a secure connection, it sent an invalid response. Vercel deployment and vanilla JS

所以我正在进一步开发这个网站,这次我添加了一个 firebase 登录名,它应该在您登录后将您重定向到主页。但是我得到 "This site can’t provide a secure connection, it sent an invalid response" 每个 window.location 方法。一旦我对该行发表评论,一切都会正常。我遍历了所有与 Whosebug 相关的问题和 js 文档,但似乎找不到答案,所以任何帮助都会很受欢迎。

var firebaseConfig = {
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
const auth = firebase.auth();

//Get Elements
const txtEmail = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin = document.getElementById('btnLogin');
const btnSignUp = document.getElementById('btnSignUp');
const btnLogOut = document.getElementById('btnLogOut');

btnLogOut.style.display= 'none'

//Add login event
btnLogin.addEventListener('click', e => {
    event.preventDefault()
    const email = txtEmail.value;
    const pass = txtPassword.value;
    //Sign In
    try {
        auth.signInWithEmailAndPassword(email, pass);
    } catch (error) {
        console.log(error.message);
    }
})

//Add SignUp Event
btnSignUp.addEventListener('click', e => {
    const email = txtEmail.value;
    const pass = txtPassword.value;
    //Sign up
    try {
        auth.createUserWithEmailAndPassword(email, pass);
    } catch (error) {
        console.log(error.message);
    }
})

btnLogOut.addEventListener('click', e => {
    event.preventDefault()
    firebase.auth().signOut();
});

firebase.auth().onAuthStateChanged(firebaseUser => {
    if(firebaseUser) {
        window.location.replace('https://www.camisite.alenieto97.now.sh/home.html')
        btnLogin.style.display = 'none'
        btnSignUp.style.display = 'none'
        btnLogOut.style.display = ''
    } else {
        console.log('not logged in')
        btnLogOut.style.display = 'none'
        btnLogin.style.display = ''
        btnSignUp.style.display = ''
    }

我删除了firebase.config的所有营地。

您是否尝试过根级别 url?这是因为如果您的应用程序托管在 http://localhost 或任何其他域中,那么您试图将 url 更改为 https://www.camisite.alenieto97.now.sh 它会抛出 SECURITY_ERROR。使用根级别 url 将解决此类问题。此外,您为什么要对可能会更改的域名进行硬编码?

firebase.auth().onAuthStateChanged(firebaseUser => {
    if(firebaseUser) {
        window.location.replace('/home.html')
        btnLogin.style.display = 'none'

好吧,Mkam 是对的。 url 是错误的。从 url.

中删除 "www." 后一切正常