Python marionette client doesn't close last window

424 views Asked by At

Here's a small program that doesn't seem to close the last tab.

from marionette_driver.marionette import Marionette

            client = Marionette("localhost", socket_timeout=30, port=proc_port)
            client.start_session()
            client.set_window_size(1024,768)
            client.close()

that will not close the last tab but if there are multiple tabs it will close one.

Calling client.quit() will throw an error.

How do I close the last tab/ window from the python marionette client?

1

There are 1 answers

0
user1610950 On

I'll go ahead and answer this one myself. After a lot of crashes, I searched down the crash string and it lead me to this file on the mozilla development network for the mariontte.py

Looking through the code I saw these lines

@do_process_check
def quit(self, in_app=False):
    """Terminate the currently running instance.

    This command will delete the active marionette session. It also allows
    manipulation of eg. the profile data while the application is not running.
    To start the application again, start_session() has to be called.

    :param in_app: If True, marionette will cause a quit from within the
                   browser. Otherwise the browser will be quit immediately
                   by killing the process.
    """
    if not self.instance:
        raise errors.MarionetteException("quit() can only be called "
                                         "on Gecko instances launched by Marionette")

I kept getting the crash quit() can only be called on Gecko instanced launched by Marionette

then I looked around and saw the force quit option so I tried that and it seems to kill the last Firefox window.

Maybe in the future Firefox team can fix this or I might be using the API wrong.

If you have more than 1 tab open you can close it by switching to that window handle and calling client.close() on that window handle.

If you only have one tab left open, that no longer works and for me I had to call

    client._send_message("quitApplication", {"flags": ["eForceQuit"]})

to close the last window and exit.