new: Autoselect browser engine based on the UA

pull/497/head
Raphaël Vinot 2022-08-19 14:26:18 +02:00
parent c1009cbc11
commit d63ea473f5
3 changed files with 57 additions and 45 deletions

View File

@ -19,7 +19,7 @@ from redis.asyncio import Redis
from playwrightcapture import Capture, PlaywrightCaptureException from playwrightcapture import Capture, PlaywrightCaptureException
from lookyloo.default import AbstractManager, get_config, get_socket_path, safe_create_dir from lookyloo.default import AbstractManager, get_config, get_socket_path, safe_create_dir
from lookyloo.helpers import get_captures_dir, load_cookies, UserAgents from lookyloo.helpers import get_captures_dir, load_cookies, UserAgents, ParsedUserAgent
from lookyloo.modules import FOX from lookyloo.modules import FOX
@ -165,6 +165,19 @@ class AsyncCapture(AbstractManager):
# Catch case where the UA is broken on the UI, and the async submission. # Catch case where the UA is broken on the UI, and the async submission.
self.user_agents.user_agents # triggers an update of the default UAs self.user_agents.user_agents # triggers an update of the default UAs
capture_ua = user_agent if user_agent else self.user_agents.default['useragent']
if not browser_engine:
# Automatically pick a browser
parsed_ua = ParsedUserAgent(capture_ua)
if not parsed_ua.browser:
browser_engine = 'webkit'
elif parsed_ua.browser.lower().startswith('chrom'):
browser_engine = 'chromium'
elif parsed_ua.browser.lower().startswith('firefox'):
browser_engine = 'firefox'
else:
browser_engine = 'webkit'
self.logger.info(f'Capturing {url}') self.logger.info(f'Capturing {url}')
try: try:
async with Capture(browser=browser_engine, device_name=device_name, proxy=proxy) as capture: async with Capture(browser=browser_engine, device_name=device_name, proxy=proxy) as capture:
@ -177,7 +190,7 @@ class AsyncCapture(AbstractManager):
# required by Mypy: https://github.com/python/mypy/issues/3004 # required by Mypy: https://github.com/python/mypy/issues/3004
capture.viewport = viewport # type: ignore capture.viewport = viewport # type: ignore
if not device_name: if not device_name:
capture.user_agent = user_agent if user_agent else self.user_agents.default['useragent'] capture.user_agent = capture_ua
await capture.initialize_context() await capture.initialize_context()
entries = await capture.capture_page(url, referer=referer) entries = await capture.capture_page(url, referer=referer)
except PlaywrightCaptureException as e: except PlaywrightCaptureException as e:

View File

@ -881,8 +881,6 @@ def capture_web():
capture_query['os'] = request.form['os'] capture_query['os'] = request.form['os']
capture_query['browser'] = request.form['browser'] capture_query['browser'] = request.form['browser']
capture_query['depth'] = request.form['depth'] if request.form.get('depth') else 1
capture_query['listing'] = True if request.form.get('listing') else False capture_query['listing'] = True if request.form.get('listing') else False
if request.form.get('referer'): if request.form.get('referer'):

View File

@ -105,7 +105,6 @@
</div> </div>
</div> </div>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
</br>
{% endif %} {% endif %}
<div class="row mb-3"> <div class="row mb-3">
@ -116,49 +115,49 @@
</div> </div>
</div> </div>
</div> </div>
<div class="prefed_selector"> <div id="prefed_selector">
<div class="row mb-3"> <div class="row mb-3">
<label for="os" class="col-sm-2 col-form-label">Operating System:</label> <label for="os" class="col-sm-2 col-form-label">Operating System:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-select" name="os" id="os"> <select class="form-select" name="os" id="os">
{% for os in user_agents.keys() %} {% for os in user_agents.keys() %}
<!-- Select the default os --> <!-- Select the default os -->
<option value="{{ os }}" {% if os==default['os'] %}selected{% endif %}>{{ os }}</option> <option value="{{ os }}" {% if os==default['os'] %}selected{% endif %}>{{ os }}</option>
{% endfor%} {% endfor%}
</select> </select>
</div>
</div> </div>
</div>
{% for os, browsers in user_agents.items() %} {% for os, browsers in user_agents.items() %}
<!-- Hide the browsers that aren't part of the default os --> <!-- Hide the browsers that aren't part of the default os -->
<div id="{{os.replace(' ', '_')}}" class="style-sub-1 row mb-3" {% if not os==default['os'] %}style="display: none;"{%endif%}> <div id="{{os.replace(' ', '_')}}" class="style-sub-1 row mb-3" {% if not os==default['os'] %}style="display: none;"{%endif%}>
<label for="browser" class="col-sm-2 col-form-label">Browser Type:</label> <label for="browser" class="col-sm-2 col-form-label">Browser Type:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<!-- Disable all the selects not related to the default os --> <!-- Disable all the selects not related to the default os -->
<select class="form-select" name="browser" {% if not os==default['os'] %}disabled{%endif%}> <select class="form-select" name="browser" {% if not os==default['os'] %}disabled{%endif%}>
{% for browser in browsers.keys()%} {% for browser in browsers.keys()%}
<!-- Select the default browser --> <!-- Select the default browser -->
<option value="{{ browser }}" {% if browser==default['browser'] %}selected{% endif %}>{{ browser }}</option> <option value="{{ browser }}" {% if browser==default['browser'] %}selected{% endif %}>{{ browser }}</option>
{% endfor%}
</select>
</div>
</div>
{% for browser, user_agents in browsers.items()%}
<!-- Hide the user agents that aren't part of the default OS and browsers that aren't part of the default os -->
<div id="{{os.replace(' ', '_')}}_{{browser.replace(' ', '_')}}" class="style-sub-2 row mb-3" {% if not os==default['os'] or not browser==default['browser']%} style="display: none;"{%endif%}>
<label for="user_agent" class="col-sm-2 col-form-label">User-Agent:</label>
<div class="col-sm-10">
<!-- Disable all the selects, unless it is in default os and browser -->
<select class="form-select" name="user_agent" {% if not os==default['os'] or not browser==default['browser'] %}disabled{%endif%}>
{% for user_agent in user_agents %}
<!-- Select the default ua -->
<option value="{{ user_agent }}" {% if user_agent==default['useragent'] %}selected{% endif %}>{{ user_agent }}</option>
{% endfor%}
</select>
</div>
</div>
{% endfor%} {% endfor%}
</select> {% endfor%}
</div>
</div>
{% for browser, user_agents in browsers.items()%}
<!-- Hide the user agents that aren't part of the default OS and browsers that aren't part of the default os -->
<div id="{{os.replace(' ', '_')}}_{{browser.replace(' ', '_')}}" class="style-sub-2 row mb-3" {% if not os==default['os'] or not browser==default['browser']%} style="display: none;"{%endif%}>
<label for="user_agent" class="col-sm-2 col-form-label">User-Agent:</label>
<div class="col-sm-10">
<!-- Disable all the selects, unless it is in default os and browser -->
<select class="form-select" name="user_agent" {% if not os==default['os'] or not browser==default['browser'] %}disabled{%endif%}>
{% for user_agent in user_agents %}
<!-- Select the default ua -->
<option value="{{ user_agent }}" {% if user_agent==default['useragent'] %}selected{% endif %}>{{ user_agent }}</option>
{% endfor%}
</select>
</div>
</div>
{% endfor%}
{% endfor%}
</div> </div>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<div class="row mb-3"> <div class="row mb-3">
@ -192,6 +191,8 @@
<div id="collapseConfigCapture" class="collapse"> <div id="collapseConfigCapture" class="collapse">
<div class="card card-body"> <div class="card card-body">
<!-- Referer -->
<div class="row mb-3"> <div class="row mb-3">
<label for="referer" class="col-sm-2 col-form-label"><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer">Referer</a>:</label> <label for="referer" class="col-sm-2 col-form-label"><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer">Referer</a>:</label>
<div class="col-sm-10"> <div class="col-sm-10">