-
Notifications
You must be signed in to change notification settings - Fork 115
Debugging with Chrome DevTools
Table of Contents
The Chrome DevTools are a set of web authoring and debugging tools built into Google Chrome. As of Node.js v6.3.1 you can use the DevTools to debug and profile your Node.js code.
Each deployed function has its own worker processe, separate from the main Emulator process. This is more secure and safer for the Emulator and simulates production, but it means there's a different debugger running for each deployed function.
-
Enable debugging:
functions config set inspect true
-
Restart the Emulator:
functions restart
You should see something like the following printed to the console:
Inspect mode is enabled for the Supervisor. Check the logs for the workers' debugger ports.
-
Deploy your function, if you haven't already.
-
Call your function to have it's worker created.
-
Check the logs to see what port the debugger is listening on.
Debugger (via --inspect) for /gcp-next-2017-agent/us-central1/helloPOST listening on port 9229. Debugger listening on port 9229. Warning: This is an experimental feature and could change at any time. To start debugging, open the following URL in Chrome: chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:9229/f836e979-c48f-4329-b2aa-81f31599a287
-
Open the printed
chrome-devtools
URI into a new tab in Chrome. -
Call your function to load its code into the debugger.
-
Set breakpoints in your function code and call it again to debug.
- https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js
- https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27
- https://mattdesl.svbtle.com/debugging-nodejs-in-chrome-devtools
- https://blog.hospodarets.com/nodejs-debugging-in-chrome-devtools
Disclaimer: This is not an official Google product.
@google-cloud/functions-emulator is currently in pre-1.0.0 development. Before the 1.0.0 release, backwards compatible changes and bug fixes will bump the patch version number and breaking changes will bump the minor version number.