2016-09-21 30 views
0

我正嘗試使用Nightmarejs從我的服務器下載其中一個PDF。我已經通過節點模塊安裝爲: -如何在NightmareJs中禁用顯示打印機提示

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]', '[email protected]') 
    .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腳本文件中的電子設置。

回答

0

該網站呼叫window.print()?如果是這樣,你可以可能逃脫定義custom preload script基於default preload script並添加打印功能的覆蓋。這應該防止出現打印對話框。從臀部開始:

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