NW.js常見問題


1.默認播放視頻沒有聲音

官方說法:

Due to the license issue, the prebuilt binaries of NW.js doesn’t support proprietary codecs, like H.264. So you can’t play MP3/MP4 with <audio> and <video> tags with prebuilt NW.js. To enable those medias, you have to build NW.js from source code by following the document of Enable Proprietary Codecs.

解決辦法:

下載nw.jsp的prebuild版本:Releases · nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt · GitHub,將ffmepg文件替換nw.js目錄中即可。

2.nw.js配置

設定全屏,總是在最前端選項,需要放到windows參數下:

 {
  "name": "test",
  "main": "index.html",
  "window": {
      "fullscreen":true,
      "always_on_top":true
  }  

}

 3.無法使用node的diskinfo模塊獲取磁盤信息,調用時會報錯模塊不存在

說明:

(1)使用nodejs內部模塊,直接使用就可以,如:

  const os = require('os');

 (2)使用第三方模塊,通過C++開發,需要安裝,這塊有點麻煩,參考:https://nwjs.readthedocs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/

(3) 使用第三方模塊,通過js開發,可以直接在nw模塊使用npm install xxx,然后整成require進行引用即可

   注:需要在應用的目錄執行npm instal xxx

 

 4.執行nw.exe 無反應

(1)dll錯誤,比如ffmepg.dll不對

(2)

 5.NW通過iframe引入頁面時,只有本地靜態頁面才能注入nw對象,網絡地址無法注入?

 6.NW應用程序自動更新

(1)   利用已有的 node-webkit-updater 機制更新,初次啟動會解壓程序文件,程序、數據文件較多會比較慢

   https://blog.csdn.net/weixin_39774865/article/details/118855814

(2)單獨開發程序做處理,可以單獨更新程序和數據,按照zip包的方式下載到臨時目錄,然后移動過來就行。數據應當支持增量更新。

7.無法使用nodejs的request模塊,如下代碼:

var request = require("request");
request({
    url: "http://localhost:5000",
    method: "GET",
    json: true,
    headers: {
        "content-type": "application/json",
    },
    body: JSON.stringify({"a":"bbb"})
}, function(error, response, body) {
	console.log(error);
    if (!error && response.statusCode == 200) {
        console.log(body) // 請求成功的處理邏輯
    }
});

  會報錯:

Error: connect ECONNREFUSED ::1:5000
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at __node_internal_exceptionWithHostPort (node:internal/errors:642:12)
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)

  在package.json中增加  "node-remote": "*://*" 也不起作用?【將localhost改為127.0.0.1就可以了,比較奇怪啊】

8.asar文件

electron 應該可以用這種文件封裝應用包,嘗試一下nwjs是否可以

https://www.cnblogs.com/cutewrp/p/14723913.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM