Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!