Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
How do you send data from a local server to background.js chrome extension?

I am having difficulties sending data from my server to background.js, going from background.js to my server works perfectly however when i do response.send() any value that is inputted into there does not show in the response.

This is on my server

app.post('/login', (request, response) => {
    const creds = JSON.stringify(request.headers.auth)
    const credsclean = creds.substring(1)
    const credsclean2 = credsclean.slice(0,-1)
    const credsarray = credsclean2.split(':')
    const cred1 = credsarray[0]
    const cred2 = credsarray[1]
    getuser(cred1).then(res => {
        let resobj = res.pop()
        let respass = resobj.password
        const decipher = cryptoJS.AES.decrypt(respass, key);
        const decipher2 = decipher.toString(cryptoJS.enc.Utf8);
        if (cred2 === decipher2 ) {
            response.status(200).send({message: `${respass}`})
        } else {
            response.status(404).send()
        }

    })
})

This is on my background.js

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.message === 'login') {
        const user1 = request.payload.email
        const user2 = request.payload.password        

        fetch('http://localhost:3000/login/', {
            method: 'POST',
            headers: {  
                "Content-Type": "application/json",
                'Auth': `${user1}:${user2}`
            }   
        })
        .then(response => {
            if (response.status == '200') {
                console.log(response)
                sendResponse('success')
            } else if (response.status == '404') {
                sendResponse('fail')
            }
        })
        .catch()
        return true
    }
});

Any help would be appreciated

Thank you so much!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda