You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using cdp.fetch.RequestPaused, requests can be blocked as expected, unless Nodriver fails to find an element using tab.find. After that, the outgoing requests stop being blocked.
The requests still go through the handler and can be displayed in the console, but I am unable to block them in any way. I also tried using fail_request to no avail (although tbf I may have used that wrong). Posting this issue to save future headaches to fellow coders because this was very painful to debug, I imagine this is not expected behaviour @ultrafunkamsterdam
Here is sample code which demonstrates the issue, keep an eye on the blue .gif logo in the middle bottom of the website, which pops up after the second find() is executed, when it should be filtered:
importasynciofromnodriverimportcdpimportnodriverasucclassTest():
asyncdefrequested_paused_handler(self, event: cdp.fetch.RequestPaused):
r=event.requestis_blocked=Trueif".gif"inr.urlelseFalseifnotis_blocked:
asyncio.create_task(
self.tab.send(
cdp.fetch.continue_request(request_id=event.request_id)
)
)
else:
s=f"BLOCKING | {r.method} | {r.url}"print(f" >>> ------------\n{s}")
asyncdefstart_test(self):
# Initialize browserself.browser=awaituc.start()
# Load blank pageself.tab=awaitself.browser.get("about:blank")
# Set up browser request filteringself.tab.add_handler(cdp.fetch.RequestPaused, self.requested_paused_handler)
# Load website, the blue logo won't appear since it's been filteredself.tab=awaitself.browser.get('https://www.berkshirehathaway.com/')
print("\nPage loaded")
awaitasyncio.sleep(5)
# This element exists in the test pageprint("\nAttempting to find existing element")
awaitself.tab.find("A Message from Warren E. Buffett")
print("Done!")
awaitasyncio.sleep(5)
# As soon as the find is called, the blue .gif logo appears in the page, and any further requests are not blockedprint("\nAttempting to find non existant element")
awaitself.tab.find("this element does not exist")
test=Test()
uc.loop().run_until_complete(test.start_test())
The text was updated successfully, but these errors were encountered:
tikene
changed the title
[
[NODRIVER] Issue with cdp.fetch.RequestPaused
Oct 10, 2024
tikene
changed the title
[NODRIVER] Issue with cdp.fetch.RequestPaused
[NODRIVER] Bug with cdp.fetch.RequestPaused
Oct 10, 2024
Managed to fix it using the following code, still curious about what could cause this behaviour but feel free to mark this issue as closed. Requests would show up as "pending" in the network tab until the find() was called
When using cdp.fetch.RequestPaused, requests can be blocked as expected, unless Nodriver fails to find an element using tab.find. After that, the outgoing requests stop being blocked.
The requests still go through the handler and can be displayed in the console, but I am unable to block them in any way. I also tried using fail_request to no avail (although tbf I may have used that wrong). Posting this issue to save future headaches to fellow coders because this was very painful to debug, I imagine this is not expected behaviour @ultrafunkamsterdam
Here is sample code which demonstrates the issue, keep an eye on the blue .gif logo in the middle bottom of the website, which pops up after the second find() is executed, when it should be filtered:
The text was updated successfully, but these errors were encountered: