0 Favourites

[UPDATED: 15.05.2018] The Big NW.js Roundup - Tips & Tricks

  • Hi, my name is TheRealDannyyy and I've decided to create this topic in order to keep

    track of the latest changes, bugs and workarounds for C2's desktop exporting method.

    (If you can't see any images or just an "image" placeholder, please disable all your script/adblockers for this website!)

    1. Getting Started

    • Installing & Updating
    • The Use Of Custom Builds

    2. Main Structure

    • Important Files & File Paths
    • How To: Modify The Package Manifest Files
    • How To: Add Chromium-Args & Js-flags

    3. Bugfixes & Workarounds

    • How To: Workaround Recording Issues & Canvas Flickering
    • How To: Workaround Steam Overlay Not Appearing (Refresh)
    • How To: Workaround Steam Overlay Not Appearing (In-Process)
    • How To: Workaround Steam Overlay Issues With Letterbox Scaling
    • How To: Open Multiple NW.js Preview Windows
    • How To: Force GC To Instantly Unload Audio From Memory

    4. Custom Features & Debugging Tools

    • How To: Speed Up The Startup Time Of Your Game By Up To 20%
    • How To: Set Your Own Application Icon
    • How To: Hide/Prevent Chrome Devtools For The End-User
    • How To: Test Your Game On Higher Framerates Than 60FPS
    • How To: Use The Built-in NW.js FPS Counter
    • How To: Secure/Hide Your Game Assets
    • How To: Modify/Remove Right-Click Context Menus
    • How To: Fetch & Make Use Of Command-line Arguments

    5. NW.js Bugreports (Github)

    • NW.js Window Size Bug
    • NW.js [v0.14.0rc1 - v0.19.0] Critical Screen Flickering Bug
    • NW.js [v0.22.0 - v0.26.6] "--in-process-gpu" Causes Severe Problems With Application Instancing
    • NW.js Mouse Pointer Problem When Right-Clicking
    • NW.js Regression in 0.27 user agent handling breaks Construct 2 content
    • NW.js 0.29.0: passing --disable-software-rasterizer appears to disable hardware acceleration

    6. References & Helpful Links

    Since Construct 2's r187 update, all NWjs related files can be downloaded from THIS place.

    The installer will do the job for you and install all the necessary files and runtime components you need.

    If you don't want to wait for the latest stable NWjs installer or would like to test out the

    latest beta builds of NWjs, you also have the option to visit THIS website and do everything on your own.

    The following is a list of all files and paths that you will surely have to visit

    at some point while working with C2 and NWjs (based on default paths).

    NWjsForC2 Source Folder

    (C:\Program Files\NWjsForC2)

    Here you can find all the base files that C2 uses for the export.

    (This is also the path where you have to paste in any custom builds.)

    C2 Folder For NWjs Files

    (...\Construct2\Construct2-Win...\exporters\html5\nwjs)

    This path holds important ".json" files and usually 2 folders "win32" and "win64" with images inside.

    "package.json" & "package-win.json"

    (...\Construct2\Construct2-Win...\exporters\html5\nwjs)

    These json files (also called manifest) contain important commands that the exported version of NWjs

    can make use of. It's recommened

    not

    to add any debugging related "Chromium-Args" in those files.

    "package-preview.json"

    (...\Construct2\Construct2-Win...\exporters\html5\nwjs)

    This json manifest for NWjs is only being used while previewing your games inside Construct 2.

    It's recommended to add all the debugging related "Chromium-Args" in this file only.

    Modifying or adding chromium args is a thing that every NWjs user has to learn and do at some point.

    The most common misconception is that you're required to do it manually for each export but that's not the case!

    Since Construct 2 is copying over the package.json file(s), it's actually easier to just edit the source files directly.

    (These files can be found inside C2's Folder For NWjs Files.)

    The majority of features or bugfixes found in this topic will require chromium-args or js-flags to

    be added to the package manifest files manually. Below you will find examples on how to do it.

    (If you would like to reset everything back to default, HERE are all files as they come with Construct 2.)

    • Open the "package.json" file(s)
    • Find the "chromium-args" property (Screenshot)
    • Add a Chromium-Arg at the correct place with 1 empty space in between other args (Screenshot)
    • Open the "package.json" file(s)
    • Find the "js-flags" property, manually add it if it's not available (Screenshot)
    • Add a JS-Flag at the correct place with 1 empty space in between other flags (Screenshot)

    Game canvas is occasionally flickering and going black for a second or two.

    Recording software randomly stops because of unknown technical reasons.

    Fixed for all NW.js versions starting from 0.19.1, use only for versions from 0.14.0rc1 to v0.19.0!

    • Open the "package.json" file(s)
    • Add --disable-direct-composition to the "chromium-args" properties

    Steam Overlay doesn't appear at all or certain features aren't working.

    The game has no moving elements that trigger a refresh on the current layout.

    This is an optional workaround and most games probably won't require this at all.

    • Add a small 2x2 sprite into one of your layouts (e.g. loader layout)
    • Add a movement behavior like rotate
    • Set the sprite opacity to 0% and make it global

    Steam Overlay doesn't appear at all or certain features aren't working.

    The game canvas refreshes constantly but it's still not working as expected.

    Steam4C2 users, please read the "Quick_Start.pdf" first before doing these steps!

    • Open the "package.json" file(s)
    • Add --in-process-gpu to the "chromium-args" properties

    The Steam Overlay doesn't scale correctly on games with letterbox scaling enabled.

    Black bars around the game canvas glitch out and the Steam Overlay is still visible.

    The Steam4C2 plugin will have this workaround included in future releases.

    • Download and install THIS plugin
    • Set the events up based on your Steam plugin (Example HERE)

    (Bugfix/Workaround provided by BackendFreak.)

    NWjs doesn't allow multiple application instances running at once.

    Previewing with multiple NWjs windows in Construct 2 doesn't work.

    WARNING: There are known issues and you might experience unexpected behavior.

    • Add the browser and keyboard plugins
    • Add the condition on button pressed
    • Add the execute javascript action and execute this code: "window.open('" & Browser.URL & "');"[/code:2xtgv874]
    • Open as many windows as you like by pressing the selected button

    Garbage Collector is not doing the job and bloats memory usage.

    Frequent game crashes related to reaching the system's memory limit.

    (HERE is an example to test if it works correctly.)

    • Open the "package.json" file(s)
    • Add --expose-gc to the "js-flags" properties
    • Execute the following JS code using the browser plugin "global.gc();"[/code:2xtgv874]

    Game takes a long time to start up. Game files are heavily compressed.

    The "package.nw" file is very large and contains a lot of assets.

    (All your assets including textures, audio and code are inside the "package.nw" file.)

    • Go to your exported Win32/Win64 folder(s)
    • Rename "package.nw" to "package.zip" and unzip it
    • Rename the unzipped folder to "package.nw" and remove all the old files

    Game is using the default NWjs icon as the window icon on Windows or OSX.

    The application icon seen inside the file browser is not using the game's custom icon.

    More recent versions of NWjs automatically use and apply the "icon-128.png" file found inside your project.

    • ~ Windows Only ~
    • Start ResHack
    • Open the nw.exe file(s)
    • Go to "Action" and then "Replace Icon"
    • Select and replace the application icon(s)
    • ~ MacOSX Only ~
    • Go to THIS website
    • Select and upload your icon (PNG format)
    • Convert and receive your new icon (ICNS format)
    • Paste your new icon into *.app/Contents/Resources

    Dev-tools can be accessed by pressing "F12".

    Users can also access dev-tools in right click menu's or similar.

    (Dev-tools could allow execution of malicious code to modify your game.)

    • Add --disable-devtools to the "chromium-args" properties (prevents the most ways to access dev-tools)
    • Install the custom "Normal" build from the NWjs downloads website (completly removes dev-tools)

    Game runs at a higher framerate than 60fps. The user's monitor runs at more than 60hz.

    Noticeable bugs for certain behaviors or game mechanics without dt (delta-time) in use.

    (V-sync is always on by default and synchronizes the game's framerate with your monitor's refresh rate.)

    • ~ Bugfix For Game Eventing ~
    • Add missing dt (delta time) multiplications (tutorial)
    • ~ Testing On Higher Framerates ~
    • Open the "package.json" file(s)
    • Add --disable-gpu-vsync to the "chromium-args" properties
    • Add --limit-fps=X to the "chromium-args" properties (X = FPS, e.g. --limit-fps=144)

    Too lazy to add a simple FPS counter to the game.

    (Chromium got you covered with a built-in FPS counter.)

    The FPS counter might not work in combination with "--disable-gpu-vsync"!

    • Open the "package.json" file(s)
    • Add --show-fps-counter to the "chromium-args" properties

    Game assets (package.nw) are out in the open. Possible risk of theft or malicious modifications.

    (It is possible to merge your game files with the executable and "hide" them for the end-user.)

    Your game might take a little longer to startup. Don't like my code? Learn how to do it yourself HERE.

    • DOWNLOAD and unzip the files (NW.js Secure Assets.bat & Readme.txt)
    • Move "NW.js Secure Assets.bat" into your exported Win32/Win64 game folder(s)
    • Execute "NW.js Secure Assets.bat" once and it will tell you when everything is done
    • Notice that your "nw.exe" file is bigger now (feel free to remove the "package.nw" file now)
    • Your game will run as usual and all your assets are now hidden inside the executable

    Customized textboxes show a right-click menu, ruining the immersion of the game.

    (Below are two possible options to deal with the right-click context menus.)

    • ~ Completly Remove Them ~
    • Add the browser plugin to your project
    • Select an event which only triggers once (e.g. inside the loader layout)
    • Add the browser action execute javascript
    • Execute the following code: "document.addEventListener('contextmenu', function(e){e.preventDefault();}, false);"[/code:2xtgv874]
    • ~ Leave "Cut", "Copy", "Paste" ~
    • Add the browser plugin to your project
    • Select an event which only triggers once (e.g. inside the loader layout)
    • Add the browser action execute javascript
    • Execute the following code: "var gui=require('nw.gui'),menu=new gui.Menu;menu.append(new gui.MenuItem({label:'Cut',click:function(){document.execCommand('cut')}})),menu.append(new gui.MenuItem({label:'Copy',click:function(){document.execCommand('copy')}})),menu.append(new gui.MenuItem({label:'Paste',click:function(){document.execCommand('paste')}})),document.addEventListener('contextmenu',function(a){a.preventDefault(),(a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||a.target.isContentEditable)&&menu.popup(a.x,a.y)});"[/code:2xtgv874]

    (Code provided by Colludium.)

    NWjs plugin can't fetch and make use of any command-line arguments.

    (The example is great in combination with Steam's launch option feature!)

    The example only allows the use of a single command-line argument!

    • DOWNLOAD the example project
    • Define the command-line argument (use the global variable)

    (Example provided by Armaldio.)

    NW.js Window Size Bug

    NW.js [v0.14.0rc1 - v0.19.0] Critical Screen Flickering Bug

    NW.js [v0.22.0 - v0.26.6] "--in-process-gpu" Causes Severe Problems With Application Instancing

    NW.js Mouse Pointer Problem When Right-Clicking

    NW.js Regression in 0.27 user agent handling breaks Construct 2 content

    NW.js 0.29.0: passing --disable-software-rasterizer appears to disable hardware acceleration

  • Great job. I'm sure I'll be visiting this thread often

  • Great post. If you'd make a tutorial of it I think more users would find it.

    Edit: In my humble opinion, the workarounds should be included in the manual. Ashley I think it's important to keep the manual up to date with information like this to inform the developers about how they can make their game working in certain situations. I don't think that it's a good practice to have them dig through forum topics or find tutorials for things that they think should work out of the box. What do you think?

  • There are two more things worth to mention.

    1. You should remove the current version of the NW.js you have currently installed before installing the new one. Otherwise your OSX export size will be huge. Some more info here:

    2. Changing the Mac icon.

    a) convert your PNG to ICNS (here for example: )

    b) copy ICNS file to [yourGameName].app/Contents/Resources

  • So the single process thing was resolved, too?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • So the single process thing was resolved, too?

    If you mean the issue with screen recording and/or screen flickering, it was not about multi processing, but yes it is resolved. Please see this post for more details:

  • BackendFreak

    Yes, this means that "--in-process-gpu" is off the table and not needed anymore?

    Btw: thanks for taking the heroic effort and putting up with all the bug reports. We were really in a tight spot with these NW.js shenanigans and now we seem to approach a point where stuff is actually usable for mass deployment again.

  • --in-process-gpu is needed for greenworks to work though, as far as I'm aware, however I've never been able to get greenworks to work.

  • Prominent

    I must say I never had a problem using Madspy's Steam plugin.

  • Prominent

    I must say I never had a problem using Madspy's Steam plugin.

    Did you try the experimental greenworks version prior to using madspy's, did you have problems with that one?

  • The experimental one never worked for me (not fully anyway).

  • Yes, this means that "--in-process-gpu" is off the table and not needed anymore?

    It is possibly not needed any more. I'm currently not able to test it, I think MadSpy might know more about that?

  • Are there more than one package.json files? I only edit the one inside package.nw o.O

    EDIT: nevermind i'm retard as always, they're in exporters\html5\nwjs

    I always used to directly edit the exported file...

  • Updated the Roundup with the following change(s):

    • Easy Way To Modify "Chromium-Args"
    • How To: Set Your Own Application Icon
    • How To: Fix Unusual NW.js MacOSX Exporting Size

    Thanks for your suggestions, keep'em coming!

  • Someone stick this post plz

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)