@@ -53,6 +53,21 @@ def uninstall_addon(id)
5353 execute :uninstall_addon , { } , { id : id }
5454 end
5555
56+ def install_web_extension ( path , allow_private_browsing : nil , permanent : nil )
57+ data = encode_extension ( path )
58+ return classic_install_web_extension ( data , permanent , allow_private_browsing ) unless bidi?
59+
60+ moz = web_extension . moz
61+ options = { allow_private_browsing :, permanent :} . compact
62+ result = moz . install ( extension_data : moz . extension_base64_encoded ( value : data ) , **options )
63+ WebDriver ::WebExtension . new ( result . extension )
64+ end
65+
66+ def uninstall_web_extension ( extension_id )
67+ bidi? ? web_extension . uninstall ( extension : extension_id ) : uninstall_addon ( extension_id )
68+ nil
69+ end
70+
5671 def full_screenshot
5772 execute :full_page_screenshot
5873 end
@@ -64,6 +79,20 @@ def context=(context)
6479 def context
6580 execute :get_context
6681 end
82+
83+ private
84+
85+ def classic_install_web_extension ( data , permanent , allow_private_browsing )
86+ if allow_private_browsing == false
87+ raise Error ::WebDriverError ,
88+ 'allow_private_browsing: false requires a BiDi session; the classic install always grants ' \
89+ 'private-browsing access'
90+ end
91+
92+ temporary = !permanent unless permanent . nil?
93+ options = { temporary : temporary , allowPrivateBrowsing : allow_private_browsing } . compact
94+ WebDriver ::WebExtension . new ( execute ( :install_addon , { } , { addon : data , **options } ) )
95+ end
6796 end # Bridge
6897 end # Firefox
6998 end # WebDriver
0 commit comments