NW.js - HOW TO: Prevent Using Local App Data on Launch of App?

422 views
Skip to first unread message

LocalAppDataIssue

unread,
Mar 19, 2019, 6:54:27 PM3/19/19
to nw.js
OS: Windows 10 Pro, Version 1809

Abstract:
I am looking to prevent a behavior that I believe is being caused by NW.js or Chrome by default on launch.
However, it seems to be modified by NW.js, in that it writes to the user's \\AppData\Local\app_name on launch where app_name comes from 'name' in the package.json ...  
And that when I look at Chrome in the same Local space there are many more directories and files.

I know that Chrome does this to install, save user info, states and other data, but I don't see any reason why an NW.js application where everything is packaged separately needs to write anything here.
I am already taking advantage of saving data in the \\Roaming\AppData\app_name directory for certain preferences, window locations, etc.


Question:
(1) How can I prevent my application from writing to \\Local\AppData\app_name?  Is it possible?
(2) If #1 is not possible, is there anyway to delete the \\Local\AppData\app_name directory and its contents on shutdown of my application?


Problem:
When I launch my application, it writes to the Local AppData space.

Preferred Solution:
Do not write anything to \\Local\AppData\app_name by default


Attempted So Far:
(1) Reading NW.js documentation
(2) Reading the Chrome documentation (looking for Chrom Args)
(3) Deleting the directory in question on shutdown with a spawned process in NW.js app, but the process seems to die on shutdown, and it clearly can't delete itself while it's still running.  So...

Next Step if No answer to #1 or #2 above..?:
Run a separate .bat file on start-up to check for when the app shuts down, and when it closes, delete the directory after the fact.  But, this is not preferred and a terrible solution.


All comments are welcome even if you can't answer my 2 questions.  Any help would be greatly appreciated.  Thank you.

richard...@gmail.com

unread,
Mar 19, 2019, 10:11:12 PM3/19/19
to nw.js
As a follow-up, I don't want to write to another directory either.

I want the application to run, and I'd like to understand why it is writing to \\AppData\Local at all as a desktop application. Any insight on how and why this works in NW would also be greatly appreciated.

chrome...@gmail.com

unread,
Mar 20, 2019, 6:43:47 PM3/20/19
to nw.js
https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md

You can set a different location in package.json using chromium-args and --user-data-dir=somewhere

For one application I work on, I need it to be gone after the application exists. I personally compile a bootstrapper that then gives a command option --user-data-dir=bootstrap_created_tmpdir when launching nw. I delete it when nw exits. I have a lot of requirements so a bootstrapper was already needed for me. This is similar to your batch file idea. I don't believe the --incognito flag works as a chromium-args, so I don't know of another way to do it.


I have other applications where I like it that it persists so I can use localStorage and cache.


Russell Valentine

richard...@gmail.com

unread,
Mar 21, 2019, 5:41:36 PM3/21/19
to nw.js
Hey Russell,
Thank you for your assistance in the matter.

I did try a variety of chromium-args and I definitely tried the --user-data-dir flag before posting here.
My hope was that if I can't keep it from writing the app_name directory into \\Local\AppData, then at least I could control where it would be written.

However, even when using the --user-data-dir flag, it still writes the CrashPad directory (see my attachment for before and after flag usage) into the same folder, and then it writes everything else to the specified location with the --user-data-dir.

The --incognito flag suggestion did get me thinking.  
I agree with you, I don't see it listed in the available flags in NW.js but I tried to get Chrome to run after deleting my Chrome directory from \\Local\AppData\Google.  
I made a copy prior to that experiment.
Even when launching chrome with the --incognito flag, it still writes to the Chrome directory.  
Maybe not the cookies, etc. that the incognito flag handles, but it does still write the Chrome directory and a large number of sub-directories.

If you have any suggestions on how you're deleting your bootstrap_created_tmpdir I'd be interested.  Or even more documentation to read through.


To All
If anyone is reading this thread (Roger ::fingers crossed::), why does NW.js write the 'app_name' folder to the \\Local\AppData\app_name at all like Chrome, or more specifically, why does it need to write anywhere for that matter like Chrome...?  
Everything in my app is packaged together, built, and in a completely separate directory.  Not to mention it is a desktop application and I store my own state information in a Roaming profile, as well as logging data.  
I don't think an app should need to write anything to that \\Local\AppData space or anywhere else for that matter because even though NW uses Chrome, the app itself shouldn't need to use the same directory structure.  
Any explanation as to why NW.js does this would be greatly appreciated.

Final Note:
The ability to either (a) prevent the creation of this app_name directory from being created or (b) automatically delete the app_name directory after shutdown, perhaps using some kind of flag, would be amazing.
I'm really hoping for (a) but I'd take (b) at this point as a workaround.

Thank you.
before_and_after_user-data-dir.jpg

Roger

unread,
Mar 21, 2019, 8:35:40 PM3/21/19
to richard...@gmail.com, nw.js
Hello,

NW is based on Chromium so it just inherits that behavior. The profile directory is used to provide disk space to support web standards like cookies, localstorage, etc. 

You could change the profile location as suggested.

Besides that, we could support an in-memory only profile like the Incognito mode in Chrome, but everything (cookies, web localstorage, etc) will be lost once application quits. Please file an issue for feature request if you need this.

Thanks,
Roger

--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rich

unread,
Mar 21, 2019, 9:26:57 PM3/21/19
to nw.js
Roger,
That would be fantastic if your suggestion works, in that it simply prevents the creation of the directory anywhere.  If that's what you're suggesting, then absolutely yes.

I was about to file a request as you suggested, but before I did, I searched and found an older issue currently on github that matches mine.
I don't want to create a duplicate, but you can see it comes up filed here: https://github.com/nwjs/nw.js/issues/6328

Thank you very much for taking the time to look at this and I think other developers would appreciate this as well.
It will provide much more control over where the application creates additional directories and files outside of our application's location. 

Regards,
Rich
Reply all
Reply to author
Forward
0 new messages