Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab stats and libwebrtc logs from WebInspector directly #24330

Conversation

youennf
Copy link
Contributor

@youennf youennf commented Feb 13, 2024

7533deb

Grab stats and libwebrtc logs from WebInspector directly
rdar://122803271
https://bugs.webkit.org/show_bug.cgi?id=269196

Reviewed by Eric Carlson and Devin Rousso.

To help web developpers, it is convenient to get access to WebRTC stats and logs.
We add a Web Inspector new function that allows to pass a JS callback to get those logs.
This can be extended in the future to rtc event logs as well.
This new function is called gatherRTCLogs and is only available in Web Inspector command line.

* LayoutTests/http/tests/inspector/gatherWebInspectorRTCLogs-expected.txt: Added.
* LayoutTests/http/tests/inspector/gatherWebInspectorRTCLogs.html: Added.
* LayoutTests/platform/glib/TestExpectations:
* LayoutTests/platform/mac-wk1/TestExpectations:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Modules/mediastream/PeerConnectionBackend.h:
(WebCore::PeerConnectionBackend::startGatheringStatLogs):
(WebCore::PeerConnectionBackend::stopGatheringStatLogs):
* Source/WebCore/Modules/mediastream/RTCController.cpp:
(WebCore::RTCController::RTCController):
(WebCore::RTCController::~RTCController):
(WebCore::RTCController::add):
(WebCore::RTCController::startGatheringLogs):
(WebCore::RTCController::stopGatheringLogs):
(WebCore::RTCController::startGatheringStatLogs):
(WebCore::RTCController::stopLoggingLibWebRTCLogs):
* Source/WebCore/Modules/mediastream/RTCController.h:
* Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::startGatheringStatLogs):
(WebCore::RTCPeerConnection::stopGatheringStatLogs):
* Source/WebCore/Modules/mediastream/RTCPeerConnection.h:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::RTCStatsLogger::toJSONString const):
(WebCore::LibWebRTCMediaEndpoint::OnStatsDelivered):
(WebCore::LibWebRTCMediaEndpoint::statsLogInterval const):
(WebCore::LibWebRTCMediaEndpoint::startRTCLogs):
(WebCore::LibWebRTCMediaEndpoint::stopRTCLogs):
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::startGatheringStatLogs):
(WebCore::LibWebRTCPeerConnectionBackend::stopGatheringStatLogs):
(WebCore::LibWebRTCPeerConnectionBackend::provideStatLogs):
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::startGatheringRTCLogs):
(WebCore::Document::stopGatheringRTCLogs):
* Source/WebCore/dom/Document.h:
* Source/WebCore/inspector/CommandLineAPIHost.cpp:
(WebCore::CommandLineAPIHost::gatherRTCLogs):
* Source/WebCore/inspector/CommandLineAPIHost.h:
* Source/WebCore/inspector/CommandLineAPIHost.idl:
* Source/WebCore/inspector/CommandLineAPIModuleSource.js:
(injectModule):
* Source/WebCore/inspector/RTCLogsCallback.h: Added.
* Source/WebCore/inspector/RTCLogsCallback.idl: Added.
* Source/WebCore/platform/SourcesLibWebRTC.txt:
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCLogSink.cpp: Added.
(WebCore::LibWebRTCLogSink::LibWebRTCLogSink):
(WebCore::LibWebRTCLogSink::~LibWebRTCLogSink):
(WebCore::toWebRTCLogLevel):
(WebCore::LibWebRTCLogSink::logMessage):
(WebCore::LibWebRTCLogSink::start):
(WebCore::LibWebRTCLogSink::stop):
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCLogSink.h: Added.
* Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
(WI.JavaScriptRuntimeCompletionProvider.get _commandLineAPIKeys):

Canonical link: https://commits.webkit.org/274946@main

6fdacdd

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 tv-sim ✅ 🧪 mac-wk2-stress
✅ 🛠 🧪 merge ✅ 🛠 watch
✅ 🛠 watch-sim

@youennf youennf self-assigned this Feb 13, 2024
@youennf youennf added the WebRTC For bugs in WebRTC label Feb 13, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 13, 2024
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 246987f to 1151853 Compare February 13, 2024 10:06
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 1151853 to ea27326 Compare February 13, 2024 10:26
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from ea27326 to 19de337 Compare February 13, 2024 10:52
@youennf youennf removed the merging-blocked Applied to prevent a change from being merged label Feb 13, 2024
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 19de337 to a7fc526 Compare February 13, 2024 11:50
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 13, 2024
@youennf youennf marked this pull request as draft February 13, 2024 14:45
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from a7fc526 to a388c40 Compare February 13, 2024 15:28
@dcrousso
Copy link
Member

i realize this is still in draft, but just wanted to give you a heads up on a few things :)

the Console API is (somewhat) standardized, so if you want to add something to console i'd recommend creating a proposal (e.g. console.screenshot) and soliciting some feedback before proceeding too far with the implementation

also, generally speaking it's strongly preferred (and potentially actually required) that all console APIs do not reveal any information about whether Web Inspector is open or not as that could be used as a sort of denial-of-service attack against developers (e.g. removing content from the DOM if Web Inspector is opened). having a callback (even if it's not guaranteed how long it'll take to be invoked) would violate that concept, and therefore not be desirable

for what it's worth, this is why Web Inspector (as well as developer tooling in most other browsers) has special functions that are exposed when evaluating in the Console (e.g. the Console Command Line API), as that's a way of ensuring that the new functionality is only exposed within Web Inspector and initiated by the developer (since the page cannot access any of the specially exposed functions). i would strongly suggest considering this approach as it does require any sort of standardization and will not undesirably expose anything about Web Inspector

@youennf
Copy link
Contributor Author

youennf commented Feb 14, 2024

@dcrousso, thanks for looking into this.
The patch is using a private identifier so I would not expect JavaScript to be able to call console.gatherRTCLogs directly.
It should be similar to queryInstances for instance.
I used the page console client infrastructure for convenience, but I'll change this to directly use a JSDOMGlobalObject function.

@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from a388c40 to 2f5589f Compare February 14, 2024 09:40
@youennf youennf removed the merging-blocked Applied to prevent a change from being merged label Feb 14, 2024
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 2f5589f to 4dcb75e Compare February 14, 2024 11:25
@youennf youennf marked this pull request as ready for review February 14, 2024 11:25
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 4dcb75e to 4bf0d09 Compare February 14, 2024 15:46
@youennf youennf marked this pull request as draft February 14, 2024 15:47
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 14, 2024
@youennf youennf removed the merging-blocked Applied to prevent a change from being merged label Feb 14, 2024
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 4bf0d09 to be4ef99 Compare February 14, 2024 17:35
@youennf youennf requested a review from dcrousso February 14, 2024 19:05
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 14, 2024
@youennf youennf marked this pull request as ready for review February 15, 2024 07:04
@youennf youennf removed the merging-blocked Applied to prevent a change from being merged label Feb 15, 2024
@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from be4ef99 to 48ba0a8 Compare February 15, 2024 14:25
Copy link
Contributor

@eric-carlson eric-carlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ given Devin's previous reviews

Copy link
Member

@dcrousso dcrousso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me for the Web Inspector bits. thanks for iterating on this with me :)

@@ -189,6 +189,8 @@ if (inspectedGlobalObject.document && inspectedGlobalObject.Node) {
};
}

CommandLineAPI.methods["gatherRTCLogs"] = function() { return CommandLineAPIHost.gatherRTCLogs(arguments[0]); };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to conditionalize this just in case ENABLE_WEB_RTC is false

so either this

if (CommandLineAPIHost.gatherRTCLogs) {
    CommandLineAPI.methods["gatherRTCLogs"] = function(callback) {
        return CommandLineAPIHost.gatherRTCLogs(callback);
    };
}

or this

CommandLineAPI.methods["gatherRTCLogs"] = function(callback) {
    return CommandLineAPIHost.gatherRTCLogs?.(callback);
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@youennf youennf force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 48ba0a8 to 6fdacdd Compare February 18, 2024 08:35
@youennf youennf added the merge-queue Applied to send a pull request to merge-queue label Feb 18, 2024
rdar://122803271
https://bugs.webkit.org/show_bug.cgi?id=269196

Reviewed by Eric Carlson and Devin Rousso.

To help web developpers, it is convenient to get access to WebRTC stats and logs.
We add a Web Inspector new function that allows to pass a JS callback to get those logs.
This can be extended in the future to rtc event logs as well.
This new function is called gatherRTCLogs and is only available in Web Inspector command line.

* LayoutTests/http/tests/inspector/gatherWebInspectorRTCLogs-expected.txt: Added.
* LayoutTests/http/tests/inspector/gatherWebInspectorRTCLogs.html: Added.
* LayoutTests/platform/glib/TestExpectations:
* LayoutTests/platform/mac-wk1/TestExpectations:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Modules/mediastream/PeerConnectionBackend.h:
(WebCore::PeerConnectionBackend::startGatheringStatLogs):
(WebCore::PeerConnectionBackend::stopGatheringStatLogs):
* Source/WebCore/Modules/mediastream/RTCController.cpp:
(WebCore::RTCController::RTCController):
(WebCore::RTCController::~RTCController):
(WebCore::RTCController::add):
(WebCore::RTCController::startGatheringLogs):
(WebCore::RTCController::stopGatheringLogs):
(WebCore::RTCController::startGatheringStatLogs):
(WebCore::RTCController::stopLoggingLibWebRTCLogs):
* Source/WebCore/Modules/mediastream/RTCController.h:
* Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::startGatheringStatLogs):
(WebCore::RTCPeerConnection::stopGatheringStatLogs):
* Source/WebCore/Modules/mediastream/RTCPeerConnection.h:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::RTCStatsLogger::toJSONString const):
(WebCore::LibWebRTCMediaEndpoint::OnStatsDelivered):
(WebCore::LibWebRTCMediaEndpoint::statsLogInterval const):
(WebCore::LibWebRTCMediaEndpoint::startRTCLogs):
(WebCore::LibWebRTCMediaEndpoint::stopRTCLogs):
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::startGatheringStatLogs):
(WebCore::LibWebRTCPeerConnectionBackend::stopGatheringStatLogs):
(WebCore::LibWebRTCPeerConnectionBackend::provideStatLogs):
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::startGatheringRTCLogs):
(WebCore::Document::stopGatheringRTCLogs):
* Source/WebCore/dom/Document.h:
* Source/WebCore/inspector/CommandLineAPIHost.cpp:
(WebCore::CommandLineAPIHost::gatherRTCLogs):
* Source/WebCore/inspector/CommandLineAPIHost.h:
* Source/WebCore/inspector/CommandLineAPIHost.idl:
* Source/WebCore/inspector/CommandLineAPIModuleSource.js:
(injectModule):
* Source/WebCore/inspector/RTCLogsCallback.h: Added.
* Source/WebCore/inspector/RTCLogsCallback.idl: Added.
* Source/WebCore/platform/SourcesLibWebRTC.txt:
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCLogSink.cpp: Added.
(WebCore::LibWebRTCLogSink::LibWebRTCLogSink):
(WebCore::LibWebRTCLogSink::~LibWebRTCLogSink):
(WebCore::toWebRTCLogLevel):
(WebCore::LibWebRTCLogSink::logMessage):
(WebCore::LibWebRTCLogSink::start):
(WebCore::LibWebRTCLogSink::stop):
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCLogSink.h: Added.
* Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
(WI.JavaScriptRuntimeCompletionProvider.get _commandLineAPIKeys):

Canonical link: https://commits.webkit.org/274946@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Grab-stats-and-libwebrtc-logs-from-WebInspector-directly branch from 6fdacdd to 7533deb Compare February 18, 2024 14:28
@webkit-commit-queue webkit-commit-queue merged commit 7533deb into WebKit:main Feb 18, 2024
@webkit-commit-queue
Copy link
Collaborator

Committed 274946@main (7533deb): https://commits.webkit.org/274946@main

Reviewed commits have been landed. Closing PR #24330 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebRTC For bugs in WebRTC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants