Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
Chrome Extension, HTTP request to NodeJS

I want to create a Chrome Extension that works with Facebook. I took random text from https://randomtextgenerator.com/ (first paragraph) and now I want to use it in my source.js to create the extension.I was told that I should send HTTP request to NodeJs to take this text and use, who knows how I can do?

NodeJS / index.js

const PORT=8888;
const axios=require("axios");
const cheerio=require("cheerio");
const express=require("express");
const {response}=require("express");

const app=express();
const url="https://randomtextgenerator.com/";

axios(url)
    .then(response=>{
        const html=response.data
        const $=cheerio.load(html);
        const articles=[];
        $("#randomtext_box", html).each(function () {
            const title=$(this).text()
            articles.push(
                title
            )
        })
        let articles1=articles.join();
        let y;
        for (let i=0; i < articles1.length; i++) {
            if (articles1[i] == ".") {
                if (articles1[i + 1] == " ") {
                    if (articles1[i+2] == "\n") {
                        y=i;
                        break;
                    }
                }
            }
        }

        let newArticles = articles1.substring(0,y+1);
        console.log(newArticles);
       
    }).catch(err=>console.log(err));

app.listen(PORT, ()=>console.log(`server runing on ${PORT}`));



Chrome Extension / source.js

function(newArticles){
    let text= `<div class="text1"></div>`
    document.body.appendChild(text);
    text.innerText=newArticles;
}

I tried it with module.exports, but the error "ERROR,document is not defined".

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda