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

Handling the goto site steps which were previously skipped in the browser steps processing #2337

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions changedetectionio/content_fetchers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def get_all_headers(self):
def browser_steps_get_valid_steps(self):
if self.browser_steps is not None and len(self.browser_steps):
valid_steps = filter(
lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one' and s['operation'] != 'Goto site'),
self.browser_steps)
lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one'),
self.browser_steps[1:]) # Skip the first one, it is already handled before the browser steps are run

return valid_steps

return None

def iterate_browser_steps(self):
def iterate_browser_steps(self, start_url):
from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface
from playwright._impl._errors import TimeoutError, Error
from changedetectionio.safe_jinja import render as jinja_render
Expand All @@ -146,6 +146,11 @@ def iterate_browser_steps(self):
if '{%' in step['selector'] or '{{' in step['selector']:
selector = jinja_render(template_str=step['selector'])

# If the operation is Goto site, change it to Goto URL and use the url as the optional value
if step['operation'] == 'Goto site':
step['operation'] = 'Goto URL'
optional_value = start_url

getattr(interface, "call_action")(action_name=step['operation'],
selector=selector,
optional_value=optional_value)
Expand Down
2 changes: 1 addition & 1 deletion changedetectionio/content_fetchers/playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def run(self,

# Run Browser Steps here
if self.browser_steps_get_valid_steps():
self.iterate_browser_steps()
self.iterate_browser_steps(start_url = url)

self.page.wait_for_timeout(extra_wait * 1000)

Expand Down
3 changes: 1 addition & 2 deletions changedetectionio/content_fetchers/puppeteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def fetch_page(self,
# Run Browser Steps here
# @todo not yet supported, we switch to playwright in this case
# if self.browser_steps_get_valid_steps():
# self.iterate_browser_steps()
# self.iterate_browser_steps(start_url = url)

await asyncio.sleep(1 + extra_wait)

Expand Down Expand Up @@ -244,4 +244,3 @@ def run(self, url, timeout, request_headers, request_body, request_method, ignor
), timeout=max_time))
except asyncio.TimeoutError:
raise(BrowserFetchTimedOut(msg=f"Browser connected but was unable to process the page in {max_time} seconds."))