Marionette
1 Introduction
Marionette lets you control the Firefox web browser via the Marionette Protocol.
To use this library, you need to have a running Firefox instance with the marionette protocol enabled. To do this, all you have to do is run the firefox binary with the -marionette flag.
2 Limitations
The protocol doesn’t (seem to) support operating on more than one page concurrently within one browser session. To get around this, simply initiate multiple browser sessions via call-with-browser!.
3 Reference
(require marionette) | package: marionette-lib |
procedure
(start-marionette! [ #:command command #:profile profile #:safe-mode? safe-mode? #:headless? headless? #:timeout timeout]) → (-> void?) command : absolute-path? = "/usr/local/bin/firefox" profile : (or/c false/c absolute-path?) = #f safe-mode? : boolean? = #t headless? : boolean? = #t timeout : exact-nonnegative-integer? = 5
procedure
(call-with-marionette! p) → any
p : (-> any)
procedure
p : (-> browser? any)
procedure
p : (-> page? any)
The command argument controls the path to the firefox binary. If not provided, the system PATH is searched along with the /Applications folder on macOS.
If profile is #f, then a temporary path si created for the profile and it it subsequently removed when the browser is stopped.
call-with-marionette! accepts the same keyword arguments that start-marionette! does. It starts the browser, applies its p argument then immediately stops the browser.
call-with-marionette/browser! composes call-with-marionette! and call-with-browser! together. Keyword arguments are passed through to start-marionette!.
call-with-marionette/browser/page! composes call-with-marionette/browser! and call-with-page! together. Keyword arguments are passed through to start-marionette!.
procedure
(call-with-browser! p [ #:host host #:port port #:capabilities capabilities]) → any p : (-> browser? any) host : non-empty-string? = "127.0.0.1" port : (integer-in 1 65535) = 2828 capabilities : capabilities? = (make-capabilities)
3.1 Browser
(require marionette/browser) | package: marionette-lib |
procedure
(browser-connect! [ #:host host #:port port #:capabilities capabilities]) → browser? host : non-empty-string? = "127.0.0.1" port : (integer-in 1 65535) = 2828 capabilities : capabilities? = (make-capabilities)
procedure
(browser-disconnect! b) → void?
b : browser?
procedure
(browser-timeouts b) → timeouts?
b : browser?
procedure
(set-browser-timeouts! b t) → void?
b : browser? t : timeouts?
procedure
(browser-viewport-size b) →
exact-nonnegative-integer? exact-nonnegative-integer? b : browser?
procedure
(set-browser-viewport-size! b w h) → void?
b : browser? w : exact-nonnegative-integer? h : exact-nonnegative-integer?
procedure
(make-browser-page! b) → page?
b : browser?
procedure
b : browser?
procedure
(browser-pages b) → (listof page?)
b : browser?
procedure
(browser-focus! b p) → void?
b : browser? p : page?
3.2 Page
(require marionette/page) | package: marionette-lib |
procedure
(page-close! p) → void?
p : page?
procedure
(page-refresh! p) → void?
p : page?
procedure
(page-go-back! p) → void?
p : page?
procedure
(page-go-forward! p) → void?
p : page?
procedure
(page-execute-async! p s arg ...) → jsexpr?
p : page? s : string? arg : any/c
procedure
(page-interactive? p) → boolean?
p : page?
procedure
(page-loaded? p) → boolean?
p : page?
procedure
(page-content p) → string?
p : page?
procedure
(set-page-content! p s) → void?
p : page? s : string?
procedure
(page-wait-for! p selector [ #:timeout timeout #:visible? visible?]) → (or/c false/c element?) p : page? selector : non-empty-string? timeout : (and/c real? (not/c negative?)) = 30 visible? : boolean? = #t
procedure
(page-query-selector! p selector) → (or/c false/c element?)
p : page? selector : non-empty-string?
procedure
(page-query-selector-all! p selector) → (listof element?)
p : page? selector : non-empty-string?
procedure
(page-alert-text p) → string?
p : page?
procedure
(page-alert-accept! p) → void?
p : page?
procedure
(page-alert-dismiss! p) → void?
p : page?
procedure
(page-alert-type! p text) → void?
p : page? text : string?
procedure
(call-with-page-screenshot! page proc [ #:full? full?]) → any page : page? proc : (-> bytes? any) full? : boolean? = #t
3.3 Element
(require marionette/element) | package: marionette-lib |
procedure
(element-click! e) → void?
e : element?
procedure
(element-clear! e) → void?
e : element?
procedure
(element-type! e text) → void
e : element? text : string?
procedure
(element-query-selector! e selector) → (or/c false/c element?)
e : element? selector : non-empty-string?
procedure
(element-query-selector-all! e selector) → (listof element?)
e : element? selector : non-empty-string?
procedure
(element-enabled? e) → boolean?
e : element?
procedure
(element-selected? e) → boolean?
e : element?
procedure
(element-visible? e) → boolean?
e : element?
procedure
(element-handle e) → handle/c
e : element?
procedure
(element-tag e) → string?
e : element?
procedure
(element-text e) → string?
e : element?
procedure
(element-rect e) → rect?
e : element?
procedure
(element-attribute e name) → (or/c false/c string?)
e : element? name : string?
procedure
(element-property e name) → (or/c false/c string?)
e : element? name : string?
3.4 Capabilities
(require marionette/capabilities) | |
package: marionette-lib |
value
page-load-strategy/c : (or/c "none" "eager" "normal")
value
unhandled-prompt-behavior/c :
(or/c "dismiss" "dismiss and notify" "accept" "accept and notify" "ignore")
struct
(struct capabilities ( timeouts page-load-strategy unhandled-prompt-behavior accept-insecure-certs?) #:extra-constructor-name make-capabilities) timeouts : timeouts? page-load-strategy : page-load-strategy/c unhandled-prompt-behavior : unhandled-prompt-behavior/c accept-insecure-certs? : boolean?
procedure
(make-capabilities [ #:timeouts timeouts #:page-load-strategy page-load-strategy #:unhandled-prompt-behavior unhandled-prompt-behavior #:accept-insecure-certs? accept-insecure-certs?]) → capabilities? timeouts : timeouts? = (make-timeouts) page-load-strategy : page-load-strategy/c = "normal"
unhandled-prompt-behavior : unhandled-prompt-behavior/c = "dismiss and notify" accept-insecure-certs? : boolean? = #f
3.5 Timeouts
(require marionette/timeouts) | package: marionette-lib |
struct
(struct timeouts (script page-load implicit) #:extra-constructor-name make-timeouts) script : exact-nonnegative-integer? page-load : exact-nonnegative-integer? implicit : exact-nonnegative-integer?
procedure
(make-timeouts [ #:script script #:page-load page-load #:implicit implicit]) → timeouts? script : exact-nonnegative-integer? = 30000 page-load : exact-nonnegative-integer? = 300000 implicit : exact-nonnegative-integer? = 0
3.6 Rect
(require marionette/rect) | package: marionette-lib |
struct
(struct rect (x y w h) #:extra-constructor-name make-rect) x : exact-integer? y : exact-integer? w : natural? h : natural?