From 784d19214c569be63efddd36a6d1d5ff440edcd2 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 25 Jul 2019 09:37:38 +0200 Subject: behavior: Ignore failed onload script injection Will be re-injected by controller anyway. --- crocoite/behavior.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'crocoite') diff --git a/crocoite/behavior.py b/crocoite/behavior.py index 4d89ae7..a12e9c2 100644 --- a/crocoite/behavior.py +++ b/crocoite/behavior.py @@ -147,16 +147,27 @@ class JsOnload (Behavior): if self.options: yield Script.fromStr (json.dumps (self.options, indent=2), f'{self.script.path}#options') - result = await tab.Runtime.callFunctionOn ( - functionDeclaration='function(options){return new this(options);}', - objectId=constructor, - arguments=[{'value': self.options}]) - self.logger.debug ('behavior onload start', - uuid='6c0605ae-93b3-46b3-b575-ba45790909a7', result=result) - result = result['result'] - assert result['type'] == 'object', result - assert result.get ('subtype') != 'error', result - self.context = result['objectId'] + + try: + result = await tab.Runtime.callFunctionOn ( + functionDeclaration='function(options){return new this(options);}', + objectId=constructor, + arguments=[{'value': self.options}]) + self.logger.debug ('behavior onload start', + uuid='6c0605ae-93b3-46b3-b575-ba45790909a7', result=result) + result = result['result'] + assert result['type'] == 'object', result + assert result.get ('subtype') != 'error', result + self.context = result['objectId'] + except TabException as e: + if e.args[0] == -32000: + # the site probably reloaded. ignore this, since we’ll be + # re-injected into the new site by the controller. + self.logger.error ('jsonload onload failed', + uuid='c151a863-78d1-41f4-a8e6-c022a6c5d252', + exception=e.args) + else: + raise async def onstop (self): tab = self.loader.tab -- cgit v1.2.3