我建立一個網站刮板作爲鉻擴展,所以我使用Node.js
。錯誤當使用幻影JS和Browserify
我使用node-horseman包來獲取數據,我想用browserify創建一個包,這樣我就可以在客戶端作爲一個正常的JavaScript中使用它,而不直接需要Node.js
。
當我通過終端($ node horsemanOriginalFile.js
)運行腳本時,它工作正常。問題是,當我創建我的bundle.js
與browserify
,並呼籲在我index.html
(內擴展名)的文件,我得到的錯誤:
Unhandled rejection TypeError: spawn is not a function at spawnPhantom (chrome-extension://minjemngfgengofcddnbgjgnpaddoimm/bundle.js:13030:19)
CODE:
horsemanOriginalFile.js
var Horseman = require('node-horseman');
var horseman = new Horseman();
horseman
.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
.open('https://somesite.com')
.wait(7000)
.html()
.log()
.close();
browserifyFileToCreateBundle.js(我運行$ node horsemanOriginalFile.js
創建bundle.js
文件)
var browserify = require('browserify');
var b = browserify();
b.add('horsemanOriginalFile.js');
const fs = require('fs');
const writable = fs.createWriteStream('bundle.js');
b.bundle().pipe(writable);
然後我調用客戶端創建bundle.js
(當我得到的錯誤那是):
指數,HTML
<html>
<head>
<meta charset="UTF-8">
<title>My Extension</title>
<script src="bundle.js"></script>
</head>
<body>
</body>
</html>
任何解決方案?
現在,僅供個人使用。你可以給我一個例子,我怎樣才能使用Express.js做到這一點呢? – Lioo