[webkit-changes] [WebKit/WebKit] a85f48: Web Inspector: Automatically connect Web Inspector...
Qianlang Chen
noreply at github.com
Wed Feb 26 14:32:11 PST 2025
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: a85f48918e3542ba0ef4e9ff3b0c3b32fc5f51c5
https://github.com/WebKit/WebKit/commit/a85f48918e3542ba0ef4e9ff3b0c3b32fc5f51c5
Author: Qianlang Chen <qianlangchen at apple.com>
Date: 2025-02-26 (Wed, 26 Feb 2025)
Changed paths:
M Source/JavaScriptCore/inspector/protocol/Inspector.json
M Source/WTF/wtf/PlatformEnableCocoa.h
M Source/WebCore/inspector/WorkerInspectorController.cpp
M Source/WebCore/inspector/WorkerInspectorController.h
M Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.h
M Source/WebCore/workers/service/context/ServiceWorkerDebuggable.cpp
M Source/WebCore/workers/service/context/ServiceWorkerDebuggable.h
M Source/WebCore/workers/service/context/ServiceWorkerInspectorProxy.cpp
M Source/WebCore/workers/service/context/ServiceWorkerInspectorProxy.h
M Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
M Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp
M Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h
Log Message:
-----------
Web Inspector: Automatically connect Web Inspector to ServiceWorker
https://bugs.webkit.org/show_bug.cgi?id=264576
rdar://114997939
Reviewed by BJ Burg.
(This work was done in collaboration with Razvan and was based on his
draft at https://github.com/WebKit/WebKit/commit/377f3e10bacc5847b25176fbc2cc0e1227ea1d95.)
This commit enables automatically inspecting and pausing the
ServiceWorkerDebuggable. The idea is similar to the same functionalities
with the JSContext/JSGlobalObjectDebuggable. The general flow is:
1. When the debuggable is first created, we optionally mark it as
inspectable.
2. As soon as the debuggable is marked inspectable, its main thread
(the thread that it was created on) gets blocked.
3. When the auto-launched Web Inspector frontend finishes initializing,
it notifies the backend.
- It's important for the debuggable to wait for this signal because
a genuine auto-inspection must appear attached to the debuggable
before it begins execution, respecting any breakpoints set early on
in its script (where auto-pausing is basically a breakpoint
before line 1).
4. The backend unpauses the blocked debuggable. If auto-pausing was
requested, tell the debugger agent to pause.
The service worker begins executing script unless its worker thread was
specified to start in the WorkerThreadStartMode::WaitForInspector.
During that waiting period, the worker thread can perform tasks sent
into its debugging run loop, until it's signaled to stop waiting and
continue to execute the script like normal. This commit makes use of
that interface to make the service worker pause (when justified, i.e.
developerExtrasEnabled) before running the above flow resembling
auto-inspecting a JSContext.
* Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:
(WebCore::threadStartModeFromSettings):
(WebCore::ServiceWorkerThread::ServiceWorkerThread):
- When there is potentially a remote inspector that would like to
auto-inspect, make it so that the thread waits on start before
executing its script.
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h:
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
(WebCore::ServiceWorkerThreadProxy::threadStartedRunningDebuggerTasks):
- Setting inspectability is step #1 in the above flow.
- In step #2, calling `debuggable->setInspectable(true)` might block
already, but we don't want that until the worker thread is setup
and have the run loop be in debug mode, so we do that in a callback
instead.
- In step #4, when connection to the inspector completes or fails,
the setInspectable call only returns then, so we unblock
the worker thread to resume code execution.
* Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.h:
* Source/WebCore/inspector/WorkerInspectorController.h:
* Source/WebCore/inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::frontendInitialized):
(WebCore::WorkerInspectorController::connectFrontend):
(WebCore::WorkerInspectorController::disconnectFrontend):
(WebCore::WorkerInspectorController::createLazyAgents):
(WebCore::WorkerInspectorController::ensureDebuggerAgent):
* Source/WebCore/workers/service/context/ServiceWorkerDebuggable.cpp:
(WebCore::ServiceWorkerDebuggable::connect):
* Source/WebCore/workers/service/context/ServiceWorkerInspectorProxy.h:
* Source/WebCore/workers/service/context/ServiceWorkerInspectorProxy.cpp:
(WebCore::ServiceWorkerInspectorProxy::connectToWorker):
- Mimic the logic for auto-inspecting a JSContext/JSGlobalObjectDebuggable.
* Source/JavaScriptCore/inspector/protocol/Inspector.json:
- Step #3 in the above flow, notify the backend when frontend
completes setting up.
* Source/WebCore/workers/service/context/ServiceWorkerDebuggable.h:
- Allow service workers to be auto-inspected. (This is checked at https://github.com/rcaliman-apple/WebKit/blob/eng/Web-Inspector-Automatically-connect-Web-Inspector-to-ServiceWorker/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.cpp#L95)
* Source/WTF/wtf/PlatformEnableCocoa.h:
- Add feature flag just in case.
Canonical link: https://commits.webkit.org/291167@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list