Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions gerapy_playwright/downloadermiddlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def from_crawler(cls, crawler):
'GERAPY_PLAYWRIGHT_DEVTOOLS', GERAPY_PLAYWRIGHT_DEVTOOLS)
cls.executable_path = settings.get(
'GERAPY_PLAYWRIGHT_EXECUTABLE_PATH', GERAPY_PLAYWRIGHT_EXECUTABLE_PATH)
cls.browser_type = settings.get(
'GERAPY_PLAYWRIGHT_BROWSER_TYPE', GERAPY_PLAYWRIGHT_BROWSER_TYPE)
cls.disable_extensions = settings.get('GERAPY_PLAYWRIGHT_DISABLE_EXTENSIONS',
GERAPY_PLAYWRIGHT_DISABLE_EXTENSIONS)
cls.hide_scrollbars = settings.get(
Expand Down Expand Up @@ -195,18 +197,19 @@ async def _process_request(self, request, spider):
# options['handleSIGTERM'] = self.handle_sigterm
# if self.handle_sighup:
# options['handleSIGHUP'] = self.handle_sighup
if self.disable_extensions is not None:
options['args'].append('--disable-extensions')
if self.hide_scrollbars is not None:
options['args'].append('--hide-scrollbars')
if self.mute_audio is not None:
options['args'].append('--mute-audio')
if self.no_sandbox is not None:
options['args'].append('--no-sandbox')
if self.disable_setuid_sandbox is not None:
options['args'].append('--disable-setuid-sandbox')
if self.disable_gpu is not None:
options['args'].append('--disable-gpu')
if self.browser_type == 'chromium':
if self.disable_extensions is not None:
options['args'].append('--disable-extensions')
if self.hide_scrollbars is not None:
options['args'].append('--hide-scrollbars')
if self.mute_audio is not None:
options['args'].append('--mute-audio')
if self.no_sandbox is not None:
options['args'].append('--no-sandbox')
if self.disable_setuid_sandbox is not None:
options['args'].append('--disable-setuid-sandbox')
if self.disable_gpu is not None:
options['args'].append('--disable-gpu')

# pretend as normal browser
_pretend = self.pretend # get global pretend setting
Expand Down Expand Up @@ -238,7 +241,7 @@ async def _process_request(self, request, spider):
'User-Agent').decode()

async with async_playwright() as playwright:
browser = await playwright.chromium.launch(**options)
browser = await getattr(playwright, self.browser_type).launch(**options)

context = await browser.new_context(
viewport={'width': self.window_width,
Expand Down
1 change: 1 addition & 0 deletions gerapy_playwright/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
GERAPY_PLAYWRIGHT_HEADLESS = True
GERAPY_PLAYWRIGHT_CHANNEL = None
GERAPY_PLAYWRIGHT_EXECUTABLE_PATH = None
GERAPY_PLAYWRIGHT_BROWSER_TYPE = 'chromium'
GERAPY_PLAYWRIGHT_SLOW_MO = None
# GERAPY_PLAYWRIGHT_IGNORE_DEFAULT_ARGS = False
# GERAPY_PLAYWRIGHT_HANDLE_SIGINT = True
Expand Down