The Big NW.js Roundup - News & Tips

7 favourites
From the Asset Store
Jump over the small square and avoid hitting it as long as you can!
  • 

    • Topic Overview

      Table Of Contents

      Getting Started

      • Installing & Updating
      • The Use Of Custom Builds

      Main Structure

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

      Bugfixes & Workarounds

      • How To: Workaround Steam Overlay Not Refreshing
      • How To: Workaround Steam Overlay Not Appearing
      • How To: Workaround Steam Overlay Rendering Above Window Title Bar
      • How To: Workaround Steam Overlay Issues With Letterbox Scaling
      • How To: Workaround incorrect window size
      • How To: Workaround Game Canvas Not Rendering At All
      • How To: Workaround Media Keys Affecting Music Playback

      Custom Features & Debugging Tools

      • How To: Speed Up The Startup Time Of Your Game
      • 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: Modify/Remove Right-Click Context Menus
      • How To: Fetch & Make Use Of Command-line Arguments
      • How To: Force GC To Instantly Unload Audio From Memory

      References

      • Helpful Links
      • External Bugreports
    • NW.js - Basics

      Getting Started

      Installing & Updating

      All NWjs related files can be downloaded from THIS website. The installer will do the job for you and install all the necessary files and runtime components you need.

      The Use Of Custom Builds

      If you don't want to wait for the latest stable NWjs installer or would like to test out the latest experimental builds of NWjs, you also have the option to visit THIS website and do everything on your own.

      Main Structure

      Important Files & File 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 if you decided to use them.

      • 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 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.

      How To: Modify The Package Manifest Files

      A common misconception is that you're required to edit the package manifest files for each export but that's not the case! Since Construct 2 is just copying the package.json files, it's easier to directly edit the source files.

      How To: Add Chromium-Args In The Package Manifest Files

      The majority of features or bugfixes found in this topic will require chromium-args (command-line arguments) to be added to the package manifest files.

      Steps To Add Chromium-Args To Package.json File(s):

      1. Open the "package.json" file(s)
      2. Find the "chromium-args" property
      3. Add a Chromium-Arg with 1 empty space in between other args (Example ➚)
    • NW.js - Workarounds

      Bugfixes & Workarounds

      How To: Workaround Steam Overlay Not Refreshing

      The Steam Overlay feels unresponsive, fails to refresh displayed content correctly.

      Steps To Add/Fix/Workaround:

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

      How To: Workaround Steam Overlay Not Appearing

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

      Steps To Add/Fix/Workaround:

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

      How To: Workaround Steam Overlay Rendering Above Window Title Bar

      The Steam Overlay renders above the window title bar on Windows 10.

      Steps To Add/Fix/Workaround:

      1. Open the "package.json" file(s)
      2. Add --disable-windows10-custom-titlebar to the "chromium-args" properties

      How To: Workaround Steam Overlay Issues With Letterbox Scaling

      The Steam Overlay doesn't scale correctly on games with letterbox scaling enabled. Black bars around the game canvas glitch out, still display the Overlay.

      Steps To Add/Fix/Workaround:

      1. Download and install THIS plugin
      2. Use action "Activate constant redraw" once (e.g. inside the loader layout)

      How To: Workaround incorrect window size

      NWjs doesn't start with the correct window size, often resulting in unexpected letterboxing.

      Steps To Add/Fix/Workaround:

      1. Add the browser plugin to your project
      2. Select an event which only triggers once (e.g. inside the loader layout)
      3. Add the browser action execute javascript
      4. Execute the following code:

      Construct 2:

      "if (!(this.runtime.firstInFullscreen || window['innerWidth'] === this.runtime.original_width && window['innerHeight'] === this.runtime.original_height))
      {
       var dh = Math.floor(this.runtime.original_height - window['innerHeight']);
       var dw = Math.floor(this.runtime.original_width - window['innerWidth']);
      
       window['resizeBy'](dw, dh);
       console.log('Resized window by w: ' + dw + ', h: ' + dh);
      }
      else
      {
       console.log('No window resize was required!');
      }"

      Construct 3:

      "var cm = this._runtime._canvasManager;
      var rt = this._runtime;
      if (!(cm.IsDocumentFullscreen() || cm._windowInnerWidth === rt._originalViewportWidth && cm._windowInnerHeight === rt._originalViewportHeight))
      {
       var dh = Math.floor(rt._originalViewportHeight - window['innerHeight']);
       var dw = Math.floor(rt._originalViewportWidth - window['innerWidth']);
      
       window['resizeBy'](dw, dh);
       console.log('Resized window by w: ' + dw + ', h: ' + dh);
      }
      else
      {
       console.log('No window resize was required!');
      }"

      (Code provided by Colludium.)

      How To: Workaround Game Canvas Not Rendering At All

      The game starts and runs fine but the canvas is black.

      Steps To Add/Fix/Workaround:

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

      How To: Workaround Media Keys Affecting Music Playback

      Some keyboards have media keys (e.g. play/pause), that can affect music playback.

      Steps To Add/Fix/Workaround:

      1. Open the "package.json" file(s)
      2. Add --disable-features=HardwareMediaKeyHandling to the "chromium-args" properties
    • NW.js - Features

      Custom Features & Debugging Tools

      How To: Speed Up The Startup Time Of Your Game

      The game takes a long time to start up. The "package.nw" file is very large and contains a lot of assets.

      Steps To Add/Fix/Workaround:

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

      How To: Set Your Own Application Icon

      The game is using the default NWjs icon as the app icon.

      Steps To Add/Fix/Workaround:

      Windows only:

      1. Convert PNG to ICO using an Online Converter [16-128px; 32bits]
      2. Start ResHack
      3. Open the nw.exe file(s)
      4. Right-click on "Icon Group" and "Replace Icon"
      5. Select and replace the application icon(s)
      6. Save and remove any backup/original files if needed

      MacOSX only:

      1. Convert PNG to ICNS using an Online Converter [128px]
      2. Paste your new icon into *.app/Contents/Resources

      How To: Hide/Prevent Chrome Devtools For The End-User

      Dev-tools can be accessed by pressing "F12". Users can also access dev-tools in right click menu's or similar.

      Steps To Add/Fix/Workaround:

      Prevent most ways to access dev-tools:

      • Add --disable-devtools to the "chromium-args" properties

      Completly remove dev-tools access:

      • Install the custom "Normal" build from the NWjs downloads website

      How To: Test Your Game On Higher Framerates Than 60FPS

      The 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.

      Steps To Add/Fix/Workaround:

      Bugfix for game eventing:

      Testing on higher framerates:

      1. Open the "package.json" file(s)
      2. Add --disable-gpu-vsync --disable-frame-rate-limit to the "chromium-args" properties

      Limiting the framerate (might not work with NWjs v0.33.0+):

      1. Open the "package.json" file(s)
      2. Add --limit-fps=X to the "chromium-args" properties (e.g. --limit-fps=144)

      How To: Use The Built-in NW.js FPS Counter

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

      Steps To Add/Fix/Workaround:

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

      How To: Modify/Remove Right-Click Context Menus

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

      Steps To Add/Fix/Workaround:

      Completly remove right-click menus:

      1. Add the browser plugin to your project
      2. Select an event which only triggers once (e.g. inside the loader layout)
      3. Add the browser action execute javascript
      4. Execute the following code:
      "document.addEventListener('contextmenu', function(e){e.preventDefault();}, false);"

      Leave "Cut", "Copy", "Paste" in right-click menus:

      1. Add the browser plugin to your project
      2. Select an event which only triggers once (e.g. inside the loader layout)
      3. Add the browser action execute javascript
      4. 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 provided by Colludium.)

      How To: Fetch & Make Use Of Command-line Arguments

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

      Steps To Add/Fix/Workaround:

      1. DOWNLOAD the example project
      2. Define the command-line argument (use the global variable)

      (Example provided by armaldio.)

      How To: Force GC To Instantly Unload Audio From Memory

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

      Steps To Add/Fix/Workaround:

      1. Open the "package.json" file(s)
      2. Add --js-flags=--expose-gc to the "chromium-args" properties
      3. Execute the following JS code using the browser plugin:
      "global.gc();"
    • NW.js - Archive

      References

      Useful Links

      External Bugreports

      • NW.js [v0.14.0rc1 - v0.19.0]: Critical Screen Flickering Bug (Open Link ➚)
      • NW.js [v0.17.5 - v0.43.0]: Window Size Bug (Open Link ➚)
      • NW.js [v0.18.1 - v0.18.4]: Gamepad API not working on Windows 10 (Open Link ➚)
      • NW.js [v0.19.0 - v0.28.0]: Mouse Pointer Problem When Right-Clicking (Open Link ➚)
      • NW.js [v0.22.0 - v0.26.0]: "--in-process-gpu" Causes Severe Problems With Application Instancing (Open Link ➚)
      • NW.js [v0.27.0 - v0.27.1]: Regression in 0.27 user agent handling breaks Construct 2 content (Open Link ➚)
      • NW.js [v0.29.0 - v0.32.0]: Custom cursor CSS not preserved in window (Open Link ➚)
      • NW.js [v0.29.0 - Before C2 r256]: passing --disable-software-rasterizer appears to disable hardware acceleration (Open Link ➚)
      • NW.js [v0.30.0 - v0.31.5]: Video Media Playback Causes Apphang/Appcrash (Open Link ➚)
      • NW.js [v0.33.0]: Gamepad API stopped working as of NW.js 0.33 (Open Link ➚)
      • NW.js [v0.41.0 - v0.42.0]: Slow Startup Performance Regression (Open Link ➚)
      • NW.js [v0.42.4 - v0.43.1]: --disable-devtools Chromium-Arg Stopped Working (Open Link ➚)
      • NW.js [v0.43.1 - v0.43.3]: [NW2] Regression in window sizing (Open Link ➚)
      • NW.js [v0.43.1 - v0.43.3]: NW2: Users can manually zoom using ALT/CTRL + Mousewheel (Open Link ➚)
      • NW.js [v0.44.0 - v0.46.0]: Window bar app icon is low quality again (Open Link ➚)
      • NW.js [v0.46.0 - ?]: Non-resizable windows don't fullscreen properly (Open Link ➚)
      • NW.js [v0.47.2 - ?]: Windows chromium-args 260 character limit (Open Link ➚)
      • NW.js [v0.50.0 - ?]: win.requestAttention() doesn't work (Open Link ➚)
      • NW.js [v0.50.0 - ?]: nwsaveas input does not trigger oncancel (Open Link ➚)
  • 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: viewtopic.php?f=146&t=181578

    2. Changing the Mac icon.

    a) convert your PNG to ICNS (here for example: https://iconverticons.com/online/)

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

  • So the single process thing was resolved, too?

  • 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:

  • 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...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)