You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 WebKit@377f3e1.)
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
0 commit comments