使用 Marionette 添加 Firefox 的第二个实例(更改端口)

Adding second instance of Firefox with Marionette (change port)

我在通过 marionette 创建两个 Firefox 实例时遇到很大困难。有一个实例工作正常:

在启用 marionette 的情况下启动 Firefox:

firefox.exe -marionette

用python控制它:

from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")

现在我想在当前客户端旁边添加第二个客户端,quick search 导致 --address 命令:

firefox.exe -marionette --address=localhost:2829

试图通过python控制它:

from marionette import Marionette
client = Marionette('localhost', port=2829)
client.start_session()
client.execute_script("alert('o hai there!');")

我似乎无法让它工作,但是:

error: [Errno 10061] No connection could be made because the target machine actively refused it

非常感谢任何帮助。

您必须使用不同的配置文件才能使 firefox 侦听不同的端口。
编辑 <path-to-profile>/prefs.js 添加以下内容并保存 当 firefox 未使用此配置文件时 ;

user_pref("marionette.defaultPrefs.port", 2829);

现在,将 firefox 启动为;

firefox -marionette --profile <path-to-profile> --new-instance&

创建新配置文件;

$ mkdir new_profile
$ firefox --profile new_profile --new-instance

并关闭火狐。现在你将拥有 new_profile/prefs.js