Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:在Rails应用程序中导出PDF时,参数列表后缺少_Javascript_Ruby On Rails_Export To Pdf - Fatal编程技术网

Javascript SyntaxError:在Rails应用程序中导出PDF时,参数列表后缺少

Javascript SyntaxError:在Rails应用程序中导出PDF时,参数列表后缺少,javascript,ruby-on-rails,export-to-pdf,Javascript,Ruby On Rails,Export To Pdf,我有一个语法错误,我很难弄清楚。下面的文件是exportPDF.js,用于在rails的后台作业中将一些数据导出为PDF 在日志中,我在运行延迟的作业时看到此错误 launchChrome().then(async chrome => { ^^^^^ SyntaxError: missing ) after argument list at createScript (vm.js:56:10) at Object.runInThis

我有一个语法错误,我很难弄清楚。下面的文件是exportPDF.js,用于在rails的后台作业中将一些数据导出为PDF

在日志中,我在运行延迟的作业时看到此错误

launchChrome().then(async chrome => {
                    ^^^^^

SyntaxError: missing ) after argument list
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
[Worker(host:MYMACBOOK-MacBook-Air.local pid:95907)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=8) (queue=default) FAILED (3 prior attempts) with Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/alexanderkehaya/Desktop/redimatch/tmp/pdfs_addresses_d88439d0d90259b6bb55908f36163450.pdf
//exportPDF.js

const chromeLauncher = require('chrome-launcher');
const argv = require('minimist')(process.argv.slice(2))
const CDP = require('chrome-remote-interface');
const file = require('fs');

const viewportWidth = 1440;
const viewportHeight =  900;
const url = argv.url
const outputFileName = argv.o

function launchChrome(headless=true) {
  return chromeLauncher.launch({
    port: 9222, // Uncomment to force a specific port of your choice.
    chromeFlags: [
      '--window-size=412,732',
      '--disable-gpu',
      headless ? '--headless' : ''
    ]
  });
}

launchChrome().then(async chrome => {
  console.log(chrome.port)

  const client = CDP({ port: chrome.port }, async (client) => {
    console.log('CDP Running')

    const {DOM, Emulation, Network, Page, Runtime} = client;

    // Enable events on domains we are interested in.
    await Page.enable();
    await DOM.enable();
    await Network.enable();
    console.log('events enabled')

  // Set up viewport resolution, etc.
    const deviceMetrics = {
      width: viewportWidth,
      height: viewportHeight,
      deviceScaleFactor: 0,
      mobile: false,
      fitWindow: false,
    };

    await Emulation.setDeviceMetricsOverride(deviceMetrics);
    await Emulation.setVisibleSize({width: viewportWidth, height: viewportHeight});
    await Page.navigate({url});

    Page.loadEventFired(async () => {
      // If the `full` CLI option was passed, we need to measure the height of
      // the rendered page and use Emulation.setVisibleSize
      const {root: {nodeId: documentNodeId}} = await DOM.getDocument();
      const {nodeId: bodyNodeId} = await DOM.querySelector({
        selector: 'body',
        nodeId: documentNodeId,
      });
      const {model: {height}} = await DOM.getBoxModel({nodeId: bodyNodeId});

      console.log('about to check window status')
      let v = await Runtime.evaluate({expression: 'window.status'})
      console.log('got first window status ' + v.result.value)

      while (!(v.result.value === 'READY FOR DOWNLOAD')) {
        console.log(v.result.value)
        v = await Runtime.evaluate({expression: 'window.status'})
      }


      const screenshot = await Page.printToPDF();
      const buffer = new Buffer(screenshot.data, 'base64');
      console.log(outputFileName)
      file.writeFile(outputFileName, buffer, 'base64', function(err) {
        if (err) {
          console.error(err);
        } else {
          console.log('PDF saved');
        }
        client.close();
        chrome.kill();
      });

    });


  })


}).catch((err) => console.log(err));
我错过了什么?我看到它确切地告诉我错误是什么,但我对JavaScript还是有点陌生,没有使用异步,也不确定错误在代码中的什么地方

如果有帮助的话,这是一个运行rails 5和ruby 2.3.3的rails应用程序


谢谢你看

试着把铬放在支架内

launchChrome().then(async (chrome) => {
更新

嘿,你的代码似乎没有语法错误。您可以验证语法


您正在使用的库可能有问题。

是的,我刚刚解决了这个问题。我使用了错误版本的节点…: