In the console of chrome devtools there is a dropdown at the top to select the execution context.
Here is an example when on www.google.com
Changing the execution context changes the available global variables and what any console invoked .js can access
I'm trying to run some javascript via ChromeDevtools Protocol using the Runtime.evaluate function and I need to run it in the worker context.
Checking the CDP docs, I see that Runtime.evaluate
takes a parameter ExecutionContextId
. I initially made the assumption that the execution contexts via the DevTools window dropdown would be the same as this parameter. The only way I've worked out how to get a list of the the current ExecutionContextId
's is to subscribe to the Runtime.executionContextCreated
event then do a Runtime.disable
followed by a Runtime.enable
which causes an ExecutionContextDiscription
to be received by the eventhandler for each loaded context.
However after looking though the ExecutionContextDescription
's returned, some match those in the dropdown, but an execution context describing the worker is never returned.
How does one execute js in a worker execution context via CDP, as is trivially done in ChromeDevtools window ?
Target.getTargets
? every target hasbrowserContextId
inTargetInfo
. – SeasoningTargetInfo
's returned (in my test here) is a SharedWorker, but thebrowserContextId
is string (eg.3EE21C36701BE09DB05708AAA333FB86
andExecutionContextId
is supposed to beinteger
. How to go from one to the other ? – Fobevaluate
doesn't accept browserContextId there. I didn't find a way. the only way I see to get executionContextId is what you describe in the question or Page.createIsolatedWorld – Seasoning