Skip to content

Commit

Permalink
inspector: introduce --experimental-network-inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Jul 3, 2024
1 parent c31467f commit 48feeb3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
12 changes: 12 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,17 @@ added:
Enable experimental support for the `https:` protocol in `import` specifiers.

### `--experimental-network-inspection`

<!-- YAML
added:
- REPLACEME
-->

> Stability: 1 - Experimental
Enable experimental support for the network inspection with Chrome DevTools.

### `--experimental-permission`

<!-- YAML
Expand Down Expand Up @@ -2847,6 +2858,7 @@ one is included in the list below.
* `--experimental-loader`
* `--experimental-modules`
* `--experimental-network-imports`
* `--experimental-network-inspection`
* `--experimental-permission`
* `--experimental-print-required-tla`
* `--experimental-require-module`
Expand Down
2 changes: 2 additions & 0 deletions doc/api/inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ added:
* `eventName` {string}
* `params` {Object}

This feature is only available with the `--experimental-network-inspection` flag enabled.

Emits a protocol event with the specified `eventName` and optional `params`. This function allows you to send
custom events that conform to the DevTools protocol, facilitating integration with debugging and inspection tools.
The emitted events can be captured by connected DevTools Frontend instances, such as Chrome DevTools.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function setupInspectorHooks() {
}

function setupNetworkInspection() {
if (!internalBinding('inspector').isEnabled()) {
if (!internalBinding('inspector').isEnabled() || !getOptionValue('--experimental-network-inspection')) {
return;
}
const dc = require('diagnostics_channel');
Expand Down
3 changes: 2 additions & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ std::unique_ptr<InspectorSession> Agent::ConnectToMainThread(

void Agent::EmitProtocolEvent(const StringView& event,
const StringView& params) {
if (!IsListening()) return;
if (!IsListening() || !env()->options()->experimental_network_inspection)
return;
client_->emitNotification(event, params);
}

Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"Directory where the V8 profiles generated by --cpu-prof will be "
"placed. Does not affect --prof.",
&EnvironmentOptions::cpu_prof_dir);
AddOption("--experimental-network-inspection",
"experimental network inspection support",
&EnvironmentOptions::experimental_network_inspection,
kAllowedInEnvvar);
AddOption(
"--heap-prof",
"Start the V8 heap profiler on start up, and write the heap profile "
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EnvironmentOptions : public Options {
uint64_t cpu_prof_interval = kDefaultCpuProfInterval;
std::string cpu_prof_name;
bool cpu_prof = false;
bool experimental_network_inspection = false;
std::string heap_prof_dir;
std::string heap_prof_name;
static const uint64_t kDefaultHeapProfInterval = 512 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-inspector-emit-protocol-event.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --inspect=0
// Flags: --inspect=0 --experimental-network-inspection

import * as common from '../common/index.mjs';

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-inspector-network-domain.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --inspect=0
// Flags: --inspect=0 --experimental-network-inspection

import * as common from '../common/index.mjs';

Expand Down

0 comments on commit 48feeb3

Please sign in to comment.