【问题标题】:How to disable showing printer prompt in NightmareJs如何在 NightmareJs 中禁用显示打印机提示
【发布时间】:2016-09-21 07:13:41
【问题描述】:

我正在尝试使用 Nightmarejs 从我的服务器下载一份 PDF。我已通过节点模块将其安装为:-

npm install nightmare

并写下以下代码:-

var Nightmare = require('nightmare');

var nightmare = Nightmare({ show: false})

nightmare
  .goto(url) // url of my site
  .size()
  .type('[name=email]', '')
  .type('[name=email]', 'test@gmail.com')
  .type('[name=password]', 'test')
  .click('#signInSubmit')
   .wait(2000)
  .pdf("test.pdf")
  .evaluate(function () {
 return document

  })
  .end()
  .then(function (result) {
 console.log(result)  
  })
  .catch(function (error) {
    console.error('Search failed:', error);
  });

它会将 PDF 文件保存到我的当前目录中,但由于我还将电子设置为 false,它不会显示浏览器,但会显示打印机设置提示进行打印,我只是不需要出现该提示。我只想知道我怎样才能做到这一点。当我用谷歌搜索时,它会给我设置静默为真,但我不知道我应该在哪里设置静默真选项。

var nightmare = Nightmare({ show: false})

我的意思是如何以及在哪里配置噩梦 js 脚本文件中的电子设置。

【问题讨论】:

    标签: node.js pdf-generation electron nightmare


    【解决方案1】:

    网站是否调用window.print()?如果是这样,您可以可能default preload script 的基础上定义custom preload script 并为打印功能添加覆盖。这应该会阻止出现打印对话框。从臀部:

    window.print = function(){
      //shows the print call in the DEBUG log
      __nightmare.ipc.send('log', 'print called');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多