Handle responses / resources as they come in
Closed this issue · 1 comments
joewreschnig commented
It would be nice to have an officially-supported API for incremental responses. Right now it's only possible to wait for page loads and specific selectors. I'd like to use ghost to instrument arbitrary page loads, looking at all resources loaded as they come in, for some period of time.
Right now I'm using something like:
def resources(session, url, **kwargs):
kwargs['wait'] = False
timeout = kwargs.pop('wait_timeout', session.wait_timeout)
session.open(url, **kwargs)
last_update = time()
while time() - last_update < timeout:
for resource in session._release_last_resources():
last_update = time()
yield resource
session.sleep()
if not session.loaded:
raise TimeoutError
for resource in resources(session, url): ...
Which works, but uses the _release_last_resources
private API.
joewreschnig commented
We ended up going with direct Qt access to get the instrumentation we wanted.