diff --git a/umbra/behaviors.d/facebook.js b/umbra/behaviors.d/facebook.js index 475e3c4..ecbd65a 100644 --- a/umbra/behaviors.d/facebook.js +++ b/umbra/behaviors.d/facebook.js @@ -8,8 +8,14 @@ var umbraAboveBelowOrOnScreen = function(e) { if (eTop < window.scrollY) { return -1; // above } else if (eTop > window.scrollY + window.innerHeight) { + // if (e.clientWidth != 0) { + // console.warn("e.clientWidth=" + e.clientWidth + " though it appears to be below the screen? e.getBoundingClientRect().top=" + eTop + " window.scrollY=" + window.scrollY + " window.innerHeight=" + window.innerHeight + " e=" + e); + // } return 1; // below } else { + // if (e.clientWidth != 0) { + // console.warn("e.clientWidth=" + e.clientWidth + " though it appears to be on screen? e.getBoundingClientRect().top=" + eTop + " window.scrollY=" + window.scrollY + " window.innerHeight=" + window.innerHeight + " e=" + e); + // } return 0; // on screen } } @@ -17,7 +23,7 @@ var umbraAboveBelowOrOnScreen = function(e) { // comments - 'a.UFIPagerLink > span, a.UFIPagerLink, span.UFIReplySocialSentenceLinkText' var UMBRA_THINGS_TO_CLICK_SELECTOR = 'a[href^="/browse/likes"], *[rel="theater"]'; var umbraAlreadyClicked = {}; -var umbraState = {'idleSince':null,'expectingSomething':null}; +var umbraState = {'idleSince':null,'expectingSomething':null,'bottomReachedScrollY':0}; var umbraIntervalFunc = function() { var closeButtons = document.querySelectorAll('a[title="Close"], a.closeTheater'); @@ -70,18 +76,22 @@ var umbraIntervalFunc = function() { } } + if (window.scrollY > umbraState.bottomReachedScrollY) { + umbraState.bottomReachedScrollY = window.scrollY; + } + if (!clickedSomething) { - if (somethingLeftAbove) { - console.log("scrolling UP because everything on this screen has been clicked but we missed something above"); - window.scrollBy(0, -500); + if (somethingLeftBelow) { + // console.log("scrolling down because everything on this screen has been clicked but there's more below document.body.clientHeight=" + document.body.clientHeight); + window.scrollBy(0, 300); umbraState.idleSince = null; - } else if (somethingLeftBelow) { - console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight=" + document.body.clientHeight); - window.scrollBy(0, 200); + } else if (umbraState.bottomReachedScrollY + window.innerHeight < document.documentElement.scrollHeight) { + // console.log("scrolling down because we haven't reached the bottom yet document.body.clientHeight=" + document.body.clientHeight); + window.scrollBy(0, 300); umbraState.idleSince = null; - } else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) { - console.log("scrolling because we're not to the bottom yet document.body.clientHeight=" + document.body.clientHeight); - window.scrollBy(0, 200); + } else if (somethingLeftAbove) { + // console.log("scrolling UP because we've already been to the bottom, everything on or below this screen has been clicked, but we missed something above"); + window.scrollBy(0, -600); umbraState.idleSince = null; } else if (umbraState.idleSince == null) { umbraState.idleSince = Date.now(); diff --git a/umbra/behaviors.py b/umbra/behaviors.py index 52bce1c..41e6055 100644 --- a/umbra/behaviors.py +++ b/umbra/behaviors.py @@ -68,7 +68,8 @@ class Behavior: self.notify_of_activity() def is_finished(self): - msg_id = self.umbra_worker.send_to_chrome(method="Runtime.evaluate", params={"expression": "umbraBehaviorFinished()"}) + msg_id = self.umbra_worker.send_to_chrome(method="Runtime.evaluate", + suppress_logging=True, params={"expression":"umbraBehaviorFinished()"}) self.waiting_result_msg_ids.append(msg_id) request_idle_timeout_sec = 30 diff --git a/umbra/browser.py b/umbra/browser.py index dd042d2..68fa49a 100644 --- a/umbra/browser.py +++ b/umbra/browser.py @@ -144,11 +144,12 @@ class Browser: self._behavior = None - def send_to_chrome(self, **kwargs): + def send_to_chrome(self, suppress_logging=False, **kwargs): msg_id = next(self.command_id) kwargs['id'] = msg_id msg = json.dumps(kwargs) - self.logger.debug('sending message to {}: {}'.format(self._websock, msg)) + if not suppress_logging: + self.logger.debug('sending message to {}: {}'.format(self._websock, msg)) self._websock.send(msg) return msg_id