Skip to content

Commit

Permalink
Selenium instance close fix for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 12, 2023
1 parent 9f00e29 commit ce8cc9f
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions addons/io_hubs_addon/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def init_browser(context):
browser = get_addon_pref(context).browser
if isWebdriverAlive():
if web_driver.name != browser.lower():
web_driver.quit()
close_browser()
create_browser_instance(context)
return False
return True
Expand All @@ -175,11 +175,27 @@ def init_browser(context):
return False


def close_browser():
global web_driver
if web_driver:
# Hack, without this the browser instances don't close the session correctly and
# you get a "[Browser] didn't shutdown correctly" message on reopen.
# Only seen in Windows so far so limiting to it for now.
import platform
if platform == "windows":
windows = web_driver.window_handles
for w in windows:
web_driver.switch_to.window(w)
web_driver.close()

web_driver.quit()
web_driver = None


def create_browser_instance(context):
global web_driver
if not web_driver or not isWebdriverAlive():
if web_driver:
web_driver.quit()
close_browser()
browser = get_addon_pref(context).browser
import os
file_path = get_browser_profile_directory(browser)
Expand Down Expand Up @@ -242,8 +258,7 @@ def execute(self, context):
return {'FINISHED'}

except Exception as err:
if web_driver:
web_driver.quit()
close_browser()
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'The room creation has failed: {err}')
return {"CANCELLED"}
Expand Down Expand Up @@ -281,6 +296,7 @@ def execute(self, context):
return {'FINISHED'}

except Exception as err:
close_browser()
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while opening the room: {err}')
return {"CANCELLED"}
Expand All @@ -298,7 +314,7 @@ def poll(cls, context: Context):

def execute(self, context):
try:
web_driver.quit()
close_browser()
return {'FINISHED'}

except Exception as err:
Expand Down Expand Up @@ -787,5 +803,4 @@ def unregister():
if load_post in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(load_post)

if web_driver:
web_driver.quit()
close_browser()

0 comments on commit ce8cc9f

Please sign in to comment.