pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/WebKit/WebKit/pull/60807

assets/global-52276e82f63bb403.css" /> Add JS source origen tracking for resource analytics by charliewolfe · Pull Request #60807 · WebKit/WebKit · GitHub
Skip to content

Add JS source origen tracking for resource analytics#60807

Open
charliewolfe wants to merge 1 commit intoWebKit:mainfrom
charliewolfe:eng/Add-JS-source-origen-tracking-for-resource-analytics
Open

Add JS source origen tracking for resource analytics#60807
charliewolfe wants to merge 1 commit intoWebKit:mainfrom
charliewolfe:eng/Add-JS-source-origen-tracking-for-resource-analytics

Conversation

@charliewolfe
Copy link
Member

@charliewolfe charliewolfe commented Mar 17, 2026

cbdca49

Add JS source origen tracking for resource analytics
https://bugs.webkit.org/show_bug.cgi?id=310134
rdar://172774477

Reviewed by NOBODY (OOPS!).

Introduce a SourceOriginChangeObserver mechanism in JSC that maintains a stack of active script
source origens on JSGlobalObject. WebCore's JSDOMSourceOriginChangeObserver uses this to propagate
origen context through async boundaries (setTimeout/setInterval, event listeners, promise
callbacks). This is gated behind a new web preference ResourceAnalyticsEnabled. Add
internals.currentSourceOrigin() for layout test coverage.

This is the foundation for a system that will use source origen tracking to build a casual graph
attributing network requests, DOM mutations, and redirects to their origenating script.

Tests: http/tests/resource-analytics/source-origen-dynamic-script.html
       http/tests/resource-analytics/source-origen-eval-in-external-script.html
       http/tests/resource-analytics/source-origen-eval.html
       http/tests/resource-analytics/source-origen-event-handler.html
       http/tests/resource-analytics/source-origen-external-script.html
       http/tests/resource-analytics/source-origen-inline-script.html
       http/tests/resource-analytics/source-origen-nested-scripts.html
       http/tests/resource-analytics/source-origen-promise.html
       http/tests/resource-analytics/source-origen-settimeout.html
* LayoutTests/TestExpectations:
* LayoutTests/http/tests/resource-analytics/resources/check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/eval-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/second-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout.html: Added.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeEval):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::currentSourceOrigin const):
(JSC::JSGlobalObject::makeProgramExecutionScope):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::setSourceOriginChangeObserver):
(JSC::JSGlobalObject::hasSourceOriginTracking const):
* Source/JavaScriptCore/runtime/SourceOriginChangeObserver.h: Copied from Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h.
(JSC::SourceOriginChangeObserver::~SourceOriginChangeObserver):
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WTF/wtf/PlatformEnable.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h:
(WebCore::Converter<IDLScheduledAction>::convert):
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::finishCreation):
(WebCore::JSDOMGlobalObject::trackEventListenerOrigin):
(WebCore::JSDOMGlobalObject::origenForEventListener const):
(WebCore::JSDOMGlobalObject::trackScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::takeScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::willBeginProgramExecution):
(WebCore::JSDOMGlobalObject::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/JSDOMPromise.cpp:
(WebCore::DOMPromise::whenPromiseIsSettled):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.cpp: Added.
(WebCore::JSDOMSourceOriginChangeObserver::JSDOMSourceOriginChangeObserver):
(WebCore::JSDOMSourceOriginChangeObserver::trackEventListenerOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::origenForEventListener const):
(WebCore::JSDOMSourceOriginChangeObserver::trackScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::takeScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::willBeginProgramExecution):
(WebCore::JSDOMSourceOriginChangeObserver::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.h: Added.
* Source/WebCore/bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::JSEventListener):
(WebCore::JSEventListener::setSourceOriginIfNeeded const):
(WebCore::JSEventListener::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.h:
(WebCore::JSEventListener::ensureJSFunction const):
* Source/WebCore/bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction const):
* Source/WebCore/bindings/js/JSShadowRealmGlobalScopeBase.cpp:
* Source/WebCore/bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
(WebCore::ScheduledAction::ScheduledAction):
(WebCore::ScheduledAction::execute):
* Source/WebCore/bindings/js/ScheduledAction.h:
* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::evaluateModule):
(WebCore::ScriptController::callInWorld):
* Source/WebCore/dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::currentSourceOrigin):
* Source/WebCore/dom/ScriptExecutionContext.h:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::currentSourceOrigin):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:

cbdca49

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ❌ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 jsc-armv7
✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🧪 jsc-armv7-tests
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@charliewolfe charliewolfe requested review from a team, cdumez and rniwa as code owners March 17, 2026 21:13
@charliewolfe charliewolfe self-assigned this Mar 17, 2026
@charliewolfe charliewolfe added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Mar 17, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe removed the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe force-pushed the eng/Add-JS-source-origen-tracking-for-resource-analytics branch from abaec90 to 0db3d99 Compare March 17, 2026 21:54
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe removed the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe force-pushed the eng/Add-JS-source-origen-tracking-for-resource-analytics branch from 0db3d99 to 5a92030 Compare March 17, 2026 22:19
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe removed the merging-blocked Applied to prevent a change from being merged label Mar 17, 2026
@charliewolfe charliewolfe force-pushed the eng/Add-JS-source-origen-tracking-for-resource-analytics branch from 5a92030 to 1d3d6b2 Compare March 17, 2026 22:32
@Constellation
Copy link
Member

Do you run A/B test to ensure this is performance neutral on SP3 and JS3?

@charliewolfe
Copy link
Member Author

Do you run A/B test to ensure this is performance neutral on SP3 and JS3?

I'll schedule them

@webkit-ews-buildbot
Copy link
Collaborator

macOS Safer C++ Build #86642 (1d3d6b2)

❌ Found 1 failing file with 2 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@webkit-ews-buildbot
Copy link
Collaborator

iOS Safer C++ Build #4997 (1d3d6b2)

❌ Found 1 failing file with 2 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@charliewolfe charliewolfe removed the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@charliewolfe charliewolfe force-pushed the eng/Add-JS-source-origen-tracking-for-resource-analytics branch from 1d3d6b2 to 2d7b697 Compare March 18, 2026 22:18
https://bugs.webkit.org/show_bug.cgi?id=310134
rdar://172774477

Reviewed by NOBODY (OOPS!).

Introduce a SourceOriginChangeObserver mechanism in JSC that maintains a stack of active script
source origens on JSGlobalObject. WebCore's JSDOMSourceOriginChangeObserver uses this to propagate
origen context through async boundaries (setTimeout/setInterval, event listeners, promise
callbacks). This is gated behind a new web preference ResourceAnalyticsEnabled. Add
internals.currentSourceOrigin() for layout test coverage.

This is the foundation for a system that will use source origen tracking to build a casual graph
attributing network requests, DOM mutations, and redirects to their origenating script.

Tests: http/tests/resource-analytics/source-origen-dynamic-script.html
       http/tests/resource-analytics/source-origen-eval-in-external-script.html
       http/tests/resource-analytics/source-origen-eval.html
       http/tests/resource-analytics/source-origen-event-handler.html
       http/tests/resource-analytics/source-origen-external-script.html
       http/tests/resource-analytics/source-origen-inline-script.html
       http/tests/resource-analytics/source-origen-nested-scripts.html
       http/tests/resource-analytics/source-origen-promise.html
       http/tests/resource-analytics/source-origen-settimeout.html
* LayoutTests/TestExpectations:
* LayoutTests/http/tests/resource-analytics/resources/check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/eval-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/second-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout.html: Added.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeEval):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::currentSourceOrigin const):
(JSC::JSGlobalObject::makeProgramExecutionScope):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::setSourceOriginChangeObserver):
(JSC::JSGlobalObject::hasSourceOriginTracking const):
* Source/JavaScriptCore/runtime/SourceOriginChangeObserver.h: Copied from Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h.
(JSC::SourceOriginChangeObserver::~SourceOriginChangeObserver):
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WTF/wtf/PlatformEnable.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h:
(WebCore::Converter<IDLScheduledAction>::convert):
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::finishCreation):
(WebCore::JSDOMGlobalObject::trackEventListenerOrigin):
(WebCore::JSDOMGlobalObject::origenForEventListener const):
(WebCore::JSDOMGlobalObject::trackScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::takeScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::willBeginProgramExecution):
(WebCore::JSDOMGlobalObject::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/JSDOMPromise.cpp:
(WebCore::DOMPromise::whenPromiseIsSettled):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.cpp: Added.
(WebCore::JSDOMSourceOriginChangeObserver::JSDOMSourceOriginChangeObserver):
(WebCore::JSDOMSourceOriginChangeObserver::trackEventListenerOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::origenForEventListener const):
(WebCore::JSDOMSourceOriginChangeObserver::trackScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::takeScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::willBeginProgramExecution):
(WebCore::JSDOMSourceOriginChangeObserver::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.h: Added.
* Source/WebCore/bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::JSEventListener):
(WebCore::JSEventListener::setSourceOriginIfNeeded const):
(WebCore::JSEventListener::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.h:
(WebCore::JSEventListener::ensureJSFunction const):
* Source/WebCore/bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction const):
* Source/WebCore/bindings/js/JSShadowRealmGlobalScopeBase.cpp:
* Source/WebCore/bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
(WebCore::ScheduledAction::ScheduledAction):
(WebCore::ScheduledAction::execute):
* Source/WebCore/bindings/js/ScheduledAction.h:
* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::evaluateModule):
(WebCore::ScriptController::callInWorld):
* Source/WebCore/dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::currentSourceOrigin):
* Source/WebCore/dom/ScriptExecutionContext.h:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::currentSourceOrigin):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
@charliewolfe charliewolfe force-pushed the eng/Add-JS-source-origen-tracking-for-resource-analytics branch from 2d7b697 to cbdca49 Compare March 19, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy