I am working in an application that uses a headless web browser, DrissionPage. The details or code are not relevant for the question.
I need to extract all fetch headers (such as cookies, user agent and others). And it needs to be using the browser console (Chromium).
In DrissionPage, I can get the result of an expression, as long as it is synchronous.
It is also possible (but not best practice) using asynchronous code, I could always do a while loop and wait until the promise is available, or insert it into the DOM from a callback and then read from DOM using drission selectors. But I would rather have a way to do it synchronously.
This is because run_js returns Any (and it does indeed return the expression result).
But run_async_js returns None.
I can get the results of a synchronous JS operation this way:
print(tab.run_js('''
(() => {
return 1;
})()
''', as_expr=True))
So my question is, how can I extract the headers that would be sent by a fetch call? Preferably without firing the request or any async code for that matter.