Code Monkey home page Code Monkey logo

Comments (7)

ultrafunkamsterdam avatar ultrafunkamsterdam commented on May 28, 2024 1

image

from undetected-chromedriver.

ultrafunkamsterdam avatar ultrafunkamsterdam commented on May 28, 2024

Return cdp.fetch.continue_request(request_id=event.request_id)

Needs to be awaited. Not tested but 99% sure

Edit: you are returning a bare CDP command as well. You need to tab.send it as well

from undetected-chromedriver.

ultrafunkamsterdam avatar ultrafunkamsterdam commented on May 28, 2024

The code below simply hangs instead of continuing.

async def receive_handler(event: cdp.fetch.RequestPaused, tab):
  print(event.resource_type)
  return await tab.send(cdp.fetch.continue_request(request_id=event.request_id))

async def main():
  options = Options()
  service = Service('C:\Program Files\Google\Chrome\Application\chrome.exe')
  driver = await start(
    service=service,
    options=options,
  )

  await cdp.fetch.enable()
  tab = driver.main_tab
  tab.add_handler(lambda e: receive_handler(e, tab))

  page = await driver.get('https://abrahamjuliot.github.io/creepjs/')
  
  input("Press Enter to continue...")
  await page.close()

if __name__ == '__main__':

  loop().run_until_complete(main())

And forgot some awaits. Untested corrected code above

from undetected-chromedriver.

namename-123 avatar namename-123 commented on May 28, 2024

Doesn't work, it says RuntimeWarning: coroutine 'receive_handler' was never awaited

from undetected-chromedriver.

namename-123 avatar namename-123 commented on May 28, 2024

Alright I just moved the receive_handler function into the main function and it works now, it's probably better to make a whole class instead.
Thanks for help!

from undetected-chromedriver.

namename-123 avatar namename-123 commented on May 28, 2024

Hmm this is odd, it "should" work now but the site never loads, rather it's stuck on loading indefinitely.
I wonder what's causing this?

from undetected-chromedriver.

ultrafunkamsterdam avatar ultrafunkamsterdam commented on May 28, 2024

this works

from nodriver import *
import asyncio



def receive_handler(event: cdp.fetch.RequestPaused, tab):
  print(event.resource_type)
  asyncio.ensure_future(tab.send(cdp.fetch.continue_request(request_id=event.request_id)))

async def main():
  driver = await start(
  )
  tab = driver.main_tab
  driver.main_tab.add_handler(cdp.fetch.RequestPaused, lambda e: receive_handler(e, tab))
  await tab.get('https://abrahamjuliot.github.io/creepjs/')
  input("Press Enter to continue...")
  await tab.close()


if __name__ == '__main__':
  loop().run_until_complete(main())
  

ofcourse it would make more sense to encapsulate it in a class

from undetected-chromedriver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.