Node.js Heap Snapshots and Google Chrome Snapshot Viewer - node.js

Is there any way to take a heap snapshot from a running Node.js process and then load it into the Google Chrome profiles viewer? It would be very awesome to be able to use the really useful Chrome profiles tab to view Node.js snapshots.
If it is possible to do, can someone provide a step-by-step of how to produce a snapshot in Node.js and then load it into Chrome?

There is an NPM module to do this.
https://github.com/bnoordhuis/node-heapdump
Just require() the module and then you can send kill -USR2 to the node process. It creates a V8 heap dump that you can view in Chrome.

Related

Capture heap snapshot (Chrome dev tools) while running Protractor tests

I want to create an automated Protractor test that creates a heap snapshot after opening the application in Chrome and after performing a series of actions via protractor.
Then to upload in Chrome dev tools in the memory tab both snapshots and compare them. The problem is that the application classes are not available in the snapshot, only test related information.
Is there a way to do this while running Protractor tests? The snapshot libraries I've tried are heapdump, v8-profiler-next and several others but with the same result.
Thanks!

Where to get a pre-built Chromium to easily do modifications?

Chromium takes too long to get compiled, like 7 hours on a regular powerful desktop. I'm thinking of some where to get a pre-built Chromium, with which I will be able to compile again only some files to re-link to make a new Chromium binary.
Possible to compile just some source code files and re-link (re-link object files)?
It's hard to build Chromium from source but it's every easy to build a new browser based on Chromium.
With GitHub Electron, any app based on it is a real Chromium browser, and developers may create custom UI for their Electron-based browsers.
However, modern browsers would require having servers for storing users' sync data, this might not be easily affordable for 1-man development army to create a new browser for the mass.
Electron app is a pack of Chromium sandbox, and Node.js backend, the 2 communicate thru' IPC as Node.js will be able to access all resources.
GitHub Electron:
https://electronjs.org

Set up and Configuration of Sampling Heap Profiler node module

I am getting very hard time to configure Sampling Heap Profiler node module.
I would like to set up this module and want to try deploying in chrome dev tool but unfortunately, there is no document about build and deployment.
Here is the npm link - https://www.npmjs.com/package/heap-profile
Any help would be greatly appreciated.
The sampling heap profiler is designed to be used programmatically in Node.js applications.
For frontend applications, you actually don't need this module. The functionality is baked into DevTools. You can find the 'Allocation Sampling' profiler in the 'Memory' tab in Chrome Devtools:

How can I debug J2V8/node.js when running within JVM?

Typically, I use node inspector (https://github.com/node-inspector/node-inspector) to debug node.js. Can this be used to attach to a remote node.js instance running in the JVM via J2V8?
Also, it looks like the dev version of node.js supports native Chrome debugging: https://github.com/nodejs/node/pull/6792. If J2V8 adopts this version of node.js, will I be able to simply attach the Chrome debugger directly to the JVM?
If the question is still relevant - I have created j2v8-debugger library.
It allows debugging J2V8 using Chrome DevTools.
Basic features like setting/removing breakpoints, step into, step out and step over, variables inspection, etc. are implemented.
It uses Stetho lib for communication with Chrome DevTools.
Also it's uses DebugHandler for accessing V8 debug information.
If you need need to debug J2V8, which runs on non-Android JVM you would need to use another lib for communication to Chrome DevTools, but likely you could re-use all the logic from this project as it's basically POJO/JSON, which are send over web socket.
Hope it could be helpful.

CRUD files on local (sandboxed) filesystem with chrome-extensions

I've been trying to do some CRUD operations to a local drive using chrome extensions.
I understand i won't be able to access the local file system directly, a sandboxed environment will do.
LocalStorage worked for data upto 5 mb. I'll be needing more.
I've found that setting "unlimitedStorage" won't grant more to the LocalStorage.
"unlimitedStorage"
Provides an unlimited quota for storing HTML5 client-side data, such as databases and local storage files. Without this permission, the extension or app is limited to 5 MB of local storage.
Note: This permission applies only to Web SQL Database and application cache (see issue 58985). Also, it doesn't currently work with wildcard subdomains such as http://*.example.com.
see chrome extension docs
I've then tried to use the FileSystemApi.
But it turned out that only chrome apps can use this api.
As far as i know I'm left with 4 other options:
WebSQL, which is deprecated.
IndexedDB, which looks promising
Application cache, referenced in the notes of the unlimitedStorage description.
Storage api, Which seems to be available for both extensions and apps
I've got a hunch that indexedDb will allow some form of CRUD. I'm reluctant to use WebSQL as it's deprecated and i've yet to find information about the Application cache, although i doubt that storing data for extensions is within the boundaries of its intended purpose.
Is it possible for chrome extensions to save, load and delete files on the local file system?
Am i misinformed about the LocalStorage Limitations or the use of the fileSystem Api in chrome extensions?
Will IndexedDB fulfill my needs?
Try with Cordova, Capacitor or similars.
In the browser, run the code in your test area, if you want to use your sandbox you need to run the application on the device (iOS, Android, Windows, Linux, etc.) and use native resources inside the sandbox, dont forget request permission.
If you work with ionic v4 you can use capacitor and mostest important is you can build for native app from web components to have your sandbox into native device!
Capacitor:
https://capacitor.ionicframework.com/docs/apis/filesystem/
Cordova:
https://cordova.apache.org/docs/en/latest/cordova/storage/storage.html

Resources