Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for passing browser options to pyppeteer #555

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tverona1
Copy link

No description provided.

@temach
Copy link

temach commented May 21, 2024

This is really useful, also faced the same issue when I wanted to pass executablePath argument when running in docker container.

Would love to see this merged.

In my case I decided to monkey patch over the original library:

from requests_html import BaseSession, HTMLSession
import asyncio
import pyppeteer


class MyBaseSession(BaseSession):
    def __init__(self, *args, **kwargs):
        super(MyBaseSession, self).__init__(*args, **kwargs)

    @property
    async def browser(self):
        if not hasattr(self, "_browser"):
            # override browser args to pass default chromium location
            self._browser = await pyppeteer.launch(executablePath="/usr/bin/chromium", ignoreHTTPSErrors=not(self.verify), headless=True, args=['--no-sandbox'])
        return self._browser


# multiple inheritance: due to how super() works
# property "browser" is searched for in HTMLSession then instead of going to BaseSession.browser as normal
# it goes to MyBaseSession where we have it overriden to pass custom pyppeteer args
class MyHTMLSession(HTMLSession, MyBaseSession):
    def __init__(self, **kwargs):
        super(MyHTMLSession, self).__init__(**kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants