daijro / hrequests

🚀 Web scraping for humans
https://daijro.gitbook.io/hrequests/
MIT License
654 stars 39 forks source link

Browser Extension interaction #11

Closed taylormock03 closed 1 year ago

taylormock03 commented 1 year ago

You currently have the ability for browsers to use extensions such as adblockers. However, there are a few extensions that I want to use that require active input (pressing a couple of buttons). Could there be a way to interact with these extensions?

daijro commented 1 year ago

Hello,

While it isn't possible to interact with the extension from the extensions bar directly (due to limitations in Playwright), it is possible to visit its options page. Here is an example with uBlock Origin on Chrome:

>>> # create page
>>> page = hrequests.render(
...     'http://www.google.com',
...     browser='chrome',
...     headless=False,
...     extensions=[r'C:\path\to\uBlock_chromium'],
... )
>>> # get the extension id
>>> ublock_id = page.extensions[0].id  # index goes by the order extensions are passed in
>>> # visit the dashboard
>>> page.url = f'chrome-extension://{ublock_id}/dashboard.html#settings.html'

The page can now be modified from here. Hope this helps!