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
posted on 2022-04-14 11:42 webjlwang 阅读(1656) 评论(0) 编辑 收藏 举报