DevTools: Implement waitForDebuggerOnStart for SharedWorker auto-attach [chromium/src : main]

0 views
Skip to first unread message

Wang Neden (Gerrit)

unread,
Oct 13, 2025, 9:32:42 AM (17 hours ago) Oct 13
to Alex Rudenko, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
Attention needed from Alex Rudenko

Wang Neden voted and added 1 comment

Votes added by Wang Neden

Auto-Submit+1

1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Wang Neden . resolved

Hi Alex,

Thanks for taking a look at this!

This CL fixes a race condition when using `Target.setAutoAttach` with `waitForDebuggerOnStart: true` for SharedWorkers. Currently, the CDP-injected script (e.g., from `Runtime.evaluate`) often executes *after* the worker's initial script, which is incorrect behavior.

The root cause is that, unlike `ServiceWorkerDevToolsManager`, the `SharedWorkerDevToolsManager` had no mechanism to notify the `BrowserAutoAttacher` about a new worker *before* it starts running. This prevented the attacher from setting the crucial `should_pause_on_start` flag in time.

To fix this, I've aligned the implementation with the established pattern in `ServiceWorkerDevToolsManager` by introducing a similar `Observer` interface. The `BrowserAutoAttacher` now observes `SharedWorkerDevToolsManager`, receives the `SharedWorkerCreated` notification, and can correctly set the pause flag to prevent the race condition.

Happy to address any feedback. Thanks

Open in Gerrit

Related details

Attention is currently required from:
  • Alex Rudenko
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
Gerrit-Change-Number: 7037151
Gerrit-PatchSet: 2
Gerrit-Owner: Wang Neden <nede...@gmail.com>
Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
Gerrit-Attention: Alex Rudenko <alexr...@chromium.org>
Gerrit-Comment-Date: Mon, 13 Oct 2025 13:31:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Alex Rudenko (Gerrit)

unread,
Oct 13, 2025, 9:35:18 AM (17 hours ago) Oct 13
to Wang Neden, Dmitry Gozman, Andrey Kosyakov, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
Attention needed from Dmitry Gozman and Wang Neden

Alex Rudenko added 1 comment

Patchset-level comments
Alex Rudenko . resolved

@dgo...@chromium.org Could you please review? I think I saw that you were working on a similar issue related to workers (or perhaps even the same underlying issue).

Open in Gerrit

Related details

Attention is currently required from:
  • Dmitry Gozman
  • Wang Neden
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
Gerrit-Change-Number: 7037151
Gerrit-PatchSet: 2
Gerrit-Owner: Wang Neden <nede...@gmail.com>
Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
Gerrit-CC: Andrey Kosyakov <ca...@chromium.org>
Gerrit-Attention: Dmitry Gozman <dgo...@chromium.org>
Gerrit-Attention: Wang Neden <nede...@gmail.com>
Gerrit-Comment-Date: Mon, 13 Oct 2025 13:34:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Dmitry Gozman (Gerrit)

unread,
Oct 13, 2025, 9:51:08 AM (16 hours ago) Oct 13
to Wang Neden, Andrey Kosyakov, Alex Rudenko, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
Attention needed from Andrey Kosyakov and Wang Neden

Dmitry Gozman added 3 comments

Patchset-level comments
Dmitry Gozman . resolved

Looks good overall, modulo legacy observers. +caseq@ FYI.

File content/browser/devtools/browser_devtools_agent_host.cc
Line 125, Patchset 2 (Latest): SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
File content/browser/devtools/shared_worker_devtools_manager.h
Line 70, Patchset 2 (Latest): base::ObserverList<Observer>::Unchecked observer_list_;
Open in Gerrit

Related details

Attention is currently required from:
  • Andrey Kosyakov
  • Wang Neden
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
    Gerrit-Change-Number: 7037151
    Gerrit-PatchSet: 2
    Gerrit-Owner: Wang Neden <nede...@gmail.com>
    Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
    Gerrit-Reviewer: Andrey Kosyakov <ca...@chromium.org>
    Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
    Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
    Gerrit-Attention: Andrey Kosyakov <ca...@chromium.org>
    Gerrit-Attention: Wang Neden <nede...@gmail.com>
    Gerrit-Comment-Date: Mon, 13 Oct 2025 13:50:24 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Wang Neden (Gerrit)

    unread,
    Oct 13, 2025, 10:31:14 AM (16 hours ago) Oct 13
    to Andrey Kosyakov, Dmitry Gozman, Alex Rudenko, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
    Attention needed from Andrey Kosyakov and Dmitry Gozman

    Wang Neden voted and added 2 comments

    Votes added by Wang Neden

    Auto-Submit+1

    2 comments

    File content/browser/devtools/browser_devtools_agent_host.cc
    Line 125, Patchset 2: SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
    Dmitry Gozman . resolved
    Wang Neden

    Hi Dmitry,

    Thanks for the great suggestions! Using `ScopedObservation` and `CheckedObserver` is definitely a much cleaner and safer approach.

    I've updated the patchset with these changes. The `BrowserAutoAttacher` now uses `ScopedObservation` to manage its observation of `SharedWorkerDevToolsManager`, and the observer itself is now a `CheckedObserver`.

    While making these changes, I noticed that the existing observations for `ServiceWorkerDevToolsManager` and `DevToolsAgentHost` in the same class still use the manual `AddObserver`/`RemoveObserver` pattern. I'm happy to refactor them to also use `ScopedObservation` in a follow-up patch to improve consistency. I've kept this CL focused on the SharedWorker fix as discussed.

    Please let me know what you think. Thanks

    File content/browser/devtools/shared_worker_devtools_manager.h
    Line 70, Patchset 2: base::ObserverList<Observer>::Unchecked observer_list_;
    Dmitry Gozman . resolved
    Wang Neden

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Andrey Kosyakov
    • Dmitry Gozman
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
      Gerrit-Change-Number: 7037151
      Gerrit-PatchSet: 3
      Gerrit-Owner: Wang Neden <nede...@gmail.com>
      Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
      Gerrit-Reviewer: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
      Gerrit-Attention: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Attention: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Comment-Date: Mon, 13 Oct 2025 14:29:24 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Dmitry Gozman <dgo...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Alex Rudenko (Gerrit)

      unread,
      2:07 AM (12 minutes ago) 2:07 AM
      to Wang Neden, Chromium LUCI CQ, Andrey Kosyakov, Dmitry Gozman, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
      Attention needed from Andrey Kosyakov, Dmitry Gozman and Wang Neden

      Alex Rudenko voted and added 1 comment

      Votes added by Alex Rudenko

      Code-Review+1

      1 comment

      File content/browser/devtools/browser_devtools_agent_host.cc
      Line 125, Patchset 2: SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
      Dmitry Gozman . resolved

      Let's use `ScopedObservation` instead. See https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/frame_auto_attacher.h;l=59-60;drc=62a9a00176f862e688fa47919ed6f19b59f77b5f;bpv=0;bpt=1 for an example.

      Wang Neden

      Hi Dmitry,

      Thanks for the great suggestions! Using `ScopedObservation` and `CheckedObserver` is definitely a much cleaner and safer approach.

      I've updated the patchset with these changes. The `BrowserAutoAttacher` now uses `ScopedObservation` to manage its observation of `SharedWorkerDevToolsManager`, and the observer itself is now a `CheckedObserver`.

      While making these changes, I noticed that the existing observations for `ServiceWorkerDevToolsManager` and `DevToolsAgentHost` in the same class still use the manual `AddObserver`/`RemoveObserver` pattern. I'm happy to refactor them to also use `ScopedObservation` in a follow-up patch to improve consistency. I've kept this CL focused on the SharedWorker fix as discussed.

      Please let me know what you think. Thanks

      Alex Rudenko

      Hi Eden, I think it would be great to also change ServiceWorkerDevToolsManager and DevToolsAgentHost to also use ScopedObservation in a follow-up CL if you are interested in doing this.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Andrey Kosyakov
      • Dmitry Gozman
      • Wang Neden
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
      Gerrit-Change-Number: 7037151
      Gerrit-PatchSet: 3
      Gerrit-Owner: Wang Neden <nede...@gmail.com>
      Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
      Gerrit-Reviewer: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
      Gerrit-Attention: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Attention: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Attention: Wang Neden <nede...@gmail.com>
      Gerrit-Comment-Date: Tue, 14 Oct 2025 06:06:17 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Dmitry Gozman <dgo...@chromium.org>
      Comment-In-Reply-To: Wang Neden <nede...@gmail.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Wang Neden (Gerrit)

      unread,
      2:15 AM (5 minutes ago) 2:15 AM
      to Alex Rudenko, Chromium LUCI CQ, Andrey Kosyakov, Dmitry Gozman, AyeAye, chromium...@chromium.org, blink-...@chromium.org, blink-work...@chromium.org, devtools-re...@chromium.org, devtools...@chromium.org, kinuko...@chromium.org
      Attention needed from Andrey Kosyakov and Dmitry Gozman

      Wang Neden added 1 comment

      File content/browser/devtools/browser_devtools_agent_host.cc
      Line 125, Patchset 2: SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
      Dmitry Gozman . resolved

      Let's use `ScopedObservation` instead. See https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/frame_auto_attacher.h;l=59-60;drc=62a9a00176f862e688fa47919ed6f19b59f77b5f;bpv=0;bpt=1 for an example.

      Wang Neden

      Hi Dmitry,

      Thanks for the great suggestions! Using `ScopedObservation` and `CheckedObserver` is definitely a much cleaner and safer approach.

      I've updated the patchset with these changes. The `BrowserAutoAttacher` now uses `ScopedObservation` to manage its observation of `SharedWorkerDevToolsManager`, and the observer itself is now a `CheckedObserver`.

      While making these changes, I noticed that the existing observations for `ServiceWorkerDevToolsManager` and `DevToolsAgentHost` in the same class still use the manual `AddObserver`/`RemoveObserver` pattern. I'm happy to refactor them to also use `ScopedObservation` in a follow-up patch to improve consistency. I've kept this CL focused on the SharedWorker fix as discussed.

      Please let me know what you think. Thanks

      Alex Rudenko

      Hi Eden, I think it would be great to also change ServiceWorkerDevToolsManager and DevToolsAgentHost to also use ScopedObservation in a follow-up CL if you are interested in doing this.

      Wang Neden

      Great! I'll create the follow-up CL for the refactoring once this one lands.
      Thanks!

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Andrey Kosyakov
      • Dmitry Gozman
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Iab60d14d30dd0a0e8634ca7637737ee5c21ecf8e
      Gerrit-Change-Number: 7037151
      Gerrit-PatchSet: 3
      Gerrit-Owner: Wang Neden <nede...@gmail.com>
      Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
      Gerrit-Reviewer: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Reviewer: Wang Neden <nede...@gmail.com>
      Gerrit-Attention: Dmitry Gozman <dgo...@chromium.org>
      Gerrit-Attention: Andrey Kosyakov <ca...@chromium.org>
      Gerrit-Comment-Date: Tue, 14 Oct 2025 06:12:36 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Dmitry Gozman <dgo...@chromium.org>
      Comment-In-Reply-To: Alex Rudenko <alexr...@chromium.org>
      Comment-In-Reply-To: Wang Neden <nede...@gmail.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages