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

339
Visualizações
phantomjs create inside express Router does not execute

I have a server with routes built with express.Router. One of the routes uses phantom.create() inside. I can't get inside the create function, it never executes (or it does but without any effect). I run this script by node ./path/to/script :

var express = require("express");
var router  = express.Router();

router.post("/my/path", function(req, res) {
  console.log('req.body.myUrl', req.body.myUrl); // this works

  var phantom = require('phantom');
  phantom.create('--debug=true', '--web-security=false', function(ph) {
    // this never happens:
    console.log('phantom');
    return res.status(200).send({ message: "asdasd" });
  });

  console.log('mamma mia') // this works
});

The server logs this:

req.body.myUrl http://myUrl
mamma mia
# and after a few minutes this:
POST /myUrl - - ms - -
# and then the entire cycle repeats infinitely automatically:
req.body.myUrl http://myUrl
mamma mia
POST /myUrl - - ms - -

When I run the same code in a live node session ($ node), everything works just fine. Any idea what's the issue here? I've was digging in the create() source, but couldn't find any trail there :/

node v6.2.0, express 4.1.0, phantomjs 2.1.1, macOS Sierra 10.12.4,

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I've only tested your code with the latest Phantom (4.0.1), so I don't know if it applies to the version you're using, but v4 throws an error regarding the arguments not being passed correctly (they should be passed as an array).

Try this:

phantom.create([ '--debug=true', '--web-security=false' ], ...);
about 4 years ago · Santiago Trujillo Relatório

0

You need to add a catch at the end of your create to remove the UnhandledPromiseRejectionWarning.

about 4 years ago · Santiago Trujillo Relatório
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