Phantom JS не запускается .create () - PullRequest
1 голос
/ 13 июля 2020

Оборудование - Macbook Pro 2019 - Catalina 10.15.5 с использованием кода Visual Studio

В моем проекте возникает следующая проблема:

На машине Linux он работает, на Windows машина работает, на моей машине НЕ работает.

Код, который не работает, вот этот.

phantom.create().then(function (ph) {
            ph.createPage().then(function (page) {
                page.property('paperSize', {
                    format: 'A4',
                    orientation: 'portrait',
                    margin: '0'
                }).then(function () {

происходит сбой в phantom.create () function.

Я попытался сделать варианты, чтобы увидеть, как создаются объекты, например,

ph = phantom.create();
            console.log('after the phantom create ');
            console.log(ph);
            console.log('this is the ph **');
                (async function (ph) {
                page = ph.createPage().then(
                    function (page) {
                        page.property('paperSize', {
                            format: 'A4',
                            orientation: 'portrait',
                            margin: '0'

По-прежнему вылетает

Использование wait и asyn c

(async function() {
            ph = await phantom.create();
            page = await instance.createPage();
            ph.createPage().then(function (page) {
                page = page;
                page.property('paperSize', {
                    format: 'A4',
                    orientation: 'portrait',
                    margin: '0'
                       }).

В терминале, когда я это делаю:

Node > require('phantom').create()

Я получаю следующее

> require('phantom').create()
Promise {
  Phantom {
  logger: 
   { info: [Function],
     debug: [Function],
     error: [Function],
     warn: [Function] },
  process: 
   ChildProcess {
     domain: [Domain],
     _events: [Object],
     _eventsCount: 2,
     _maxListeners: undefined,
     _closesNeeded: 3,
     _closesGot: 0,
     connected: false,
     signalCode: null,
     exitCode: null,
     killed: false,
     spawnfile: '/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs',
     _handle: [Process],
     spawnargs: [Array],
     pid: 14804,
     stdin: [Socket],
     stdout: [Socket],
     stderr: [Socket],
     stdio: [Array] },
  commands: Map {},
  events: Map {},
  heartBeatId: 
   Timeout {
     _called: false,
     _idleTimeout: 100,
     _idlePrev: [TimersList],
     _idleNext: [TimersList],
     _idleStart: 3640,
     _onTimeout: [Function: bound heartBeat],
     _timerArgs: undefined,
     _repeat: 100,
     _destroyed: false,
     domain: [Domain],
     [Symbol(asyncId)]: 40,
     [Symbol(triggerAsyncId)]: 6 } },
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }

Когда я использую отладчик, он вылетает в строке

ph = phantom.create();

и возобновите отладчик, а затем приостановите его на async_hooks. js - строка const fn = function (asyncId) дает бесконечный l oop до тех пор, пока я не получу тайм-аут.

function emitHookFactory(symbol, name) {
  // Called from native. The asyncId stack handling is taken care of there
  // before this is called.
  // eslint-disable-next-line func-style
  const fn = function(asyncId) {
    active_hooks.call_depth += 1;
    // Use a single try/catch for all hook to avoid setting up one per
    // iteration.
    try {
      for (var i = 0; i < active_hooks.array.length; i++) {
        if (typeof active_hooks.array[i][symbol] === 'function') {
          active_hooks.array[i][symbol](asyncId);
        }
      }

Я также попытался изменить запуск. json и добавить

"skipFiles": [
        "inspector_async_hook.js",
        "async_hooks.js",
        "node_internals/**/*.js"
        ],

Все еще зависает на async_hooks. js хотя.

Есть идеи, что может быть причиной? Должен ли я перейти на компьютер Windows?

А пока я устанавливаю виртуальную машину.

...