我很难通过木偶创建两个火狐实例。拥有一个实例可以正常工作:
在启用木偶的情况下启动 Firefox:
firefox.exe -marionette
用python控制它:
from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")
现在我想在当前客户端旁边添加第二个客户端,快速搜索结果为 --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 -marionette --profile <path-to-profile> --new-instance&
创建新的配置文件;
$ mkdir new_profile
$ firefox --profile new_profile --new-instance
并关闭火狐浏览器。现在您将拥有new_profile/prefs.js
距离上次回复已经有一段时间了,所以一个小更新
目前(Firefox版本103+)必须设置首选项称为
marionette.port
所以,你必须设置
user_pref("marionette.port", 2829);
所有过程如下所示:
$ firefox -CreateProfile "p2829 /tmp/ff_p2829"
$ vi /tmp/ff_p2829/prefs.js #new file
> enter user_pref("marionette.port", 2829);
$ firefox -marionette -profile /tmp/ff_p2829/ -new-instance
现在 Firefox 木偶服务器侦听端口 2829