Auto-Submit | +1 |
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
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
@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).
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Looks good overall, modulo legacy observers. +caseq@ FYI.
SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
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.
base::ObserverList<Observer>::Unchecked observer_list_;
Let's use `CheckedObserver` instead. See https://source.chromium.org/chromium/chromium/src/+/main:base/observer_list.h;l=29;drc=62a9a00176f862e688fa47919ed6f19b59f77b5f;bpv=0;bpt=1 for details.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Auto-Submit | +1 |
SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
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.
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
base::ObserverList<Observer>::Unchecked observer_list_;
Let's use `CheckedObserver` instead. See https://source.chromium.org/chromium/chromium/src/+/main:base/observer_list.h;l=29;drc=62a9a00176f862e688fa47919ed6f19b59f77b5f;bpv=0;bpt=1 for details.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
Wang NedenLet'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.
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
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.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
SharedWorkerDevToolsManager::GetInstance()->AddObserver(this);
Wang NedenLet'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.
Alex RudenkoHi 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
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.
Great! I'll create the follow-up CL for the refactoring once this one lands.
Thanks!
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |