Windows 7, 8
Any NW.js version since v0.10.3 (september 2014)
Unable to make an NW.js application that open files on Windows (or to pass a filepath as first argument).
The official specification (Handling files and arguments) is outdated or does not work as described in Windows. No newer specification discuss this functionality.
This issue has already been reported many times #2416 #4951 #2525
Since then no fix has been given, despite it's an essential function for any desktop application.
Create two files named "package.json" and "app.html" inside a folder named "app.nw" :
{
"name": "Test",
"main": "app.html",
"version": "0.1.0",
"description": "Test App"
}
<html>
<body>
<script>
/* As described on https://github.com/nwjs/nw.js/wiki/Handling-files-and-arguments */
var gui = require('nw.gui');
document.write(gui.App.argv);
gui.App.on('open', function(cmdline) {
document.write('command line: ' + cmdline);
});
</script>
</body>
</html>
Then package your app using for instance nwjs-builder : nwb nwbuild app.nw
Finally, right-click any file on your computer, then click "Open with..." and select the previously build Test.exe
Result : nothing happens (app crash on loading).
You can also try the command line : .\Test.exe credits.html
The app will crash on loading if the file "credits.html" exists, but works well otherwise.
I have the same issue
I encountered this as well
@rogerwang This issue still occurs in v0.21.3. Other similar issues have been marked as fixed (e.g., https://github.com/nwjs/nw.js/issues/4681) - what's the status?
This is an important feature for my application and many others, as you can see from the number of tickets raised.
I can confirm.
Same Problem here!
I can reproduce this issue with the reporter's codes in the bugs. My Steps:
Windows 8(nwjs-sdk-v0.21.5):
package.nw, including app.html and package.json.copy /b nw.exe+package.nw app.exeapp.exe 1.html -->1.html is a nonexistent fileapp.exe app.html -->valid file_Results:_
Step 3: works well, opens a window and displays 1.html
Step 4: nothing happens, no window opens
Linux(nwjs-sdk-v0.21.5):
package.nw, including app.html and package.json.cat nw package.nw > app && chmod +x app./app 1.html -->1.html is a nonexistent file./app app.html -->valid file_Results:_
Step 3: works well, opens a window and displays 1.html
Step 4: throws errors in the console, fails to open a window
(function (exports, require, module, __filename, __dirname) { <!DOCTYPE html>
^
SyntaxError: Unexpected token <
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:567:28)
at Object.Module._extensions..js (module.js:610:10)
at Module.load (module.js:512:32)
at tryModuleLoad (module.js:471:12)
at Function.Module._load (module.js:463:3)
at Module.runMain (module.js:647:10)
at run (bootstrap_node.js:431:7)
at startup (bootstrap_node.js:164:9)
Will look to fix it soon.
@Christywl I followed the same steps as yours on windows. step 3 works well. Please check again.
@rogerwang , yes, checked on another Windows. It works well. Update my previous comment.
This is fixed in git and will be available in the next nightly build.
This fixes the problem I had. Thanks!
Most helpful comment
This is fixed in git and will be available in the next nightly build.