-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#lang racket/base | ||
|
||
(require marionette | ||
web-server/servlet | ||
(only-in xml current-unescaped-tags html-unescaped-tags)) | ||
|
||
(current-unescaped-tags html-unescaped-tags) | ||
|
||
(define ((app n) _req) | ||
(send/suspend/dispatch | ||
(lambda (embed/url) | ||
(sleep 1) | ||
(response/xexpr | ||
#:preamble #"<!DOCTYPE html>" | ||
`(html | ||
(head | ||
(script ([src "https://cdn.jsdelivr.net/npm/unpoly@3.10.2/unpoly.min.js"]))) | ||
(body | ||
(div.content | ||
(p ,(format "Counter: ~a" n)) | ||
(a | ||
([class "continue-button"] | ||
[href ,(embed/url (app (add1 n)))] | ||
[up-target ".content"]) | ||
"Continue")))))))) | ||
|
||
(define (run-marionette port) | ||
(call-with-marionette/browser/page! | ||
#:headless? #f | ||
(lambda (p) | ||
(page-goto! p (format "http://127.0.0.1:~a" port)) | ||
(define e (page-change-evt p)) | ||
(element-click! (page-wait-for! p ".continue-button")) | ||
(println (page-url p)) | ||
(println `(sync-result ,(sync e))) | ||
(println (page-url p))))) | ||
|
||
(module+ main | ||
(require racket/async-channel | ||
web-server/servlet-dispatch | ||
web-server/web-server) | ||
|
||
(define port-or-exn-ch | ||
(make-async-channel)) | ||
(define stop | ||
(serve | ||
#:confirmation-channel port-or-exn-ch | ||
#:dispatch (dispatch/servlet (app 1)) | ||
#:port 0)) | ||
(define port-or-exn | ||
(sync port-or-exn-ch)) | ||
(when (exn:fail? port-or-exn) | ||
(raise port-or-exn)) | ||
(define marionette-thd | ||
(thread | ||
(lambda () | ||
(run-marionette port-or-exn)))) | ||
(with-handlers ([exn:break? void]) | ||
(sync/enable-break marionette-thd)) | ||
(stop)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
return (window.$$marionette || {}).PageChangeToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const Marionette = window.$$marionette || {}; | ||
if (Marionette.PageChangeToken === undefined) { | ||
Marionette.PageChangeToken = arguments[0]; | ||
if (Marionette.patchedHistory === undefined) { | ||
Marionette.patchedHistory = true; | ||
for (const method of ["pushState", "replaceState"]) { | ||
window.history[method] = new Proxy(window.history[method], { | ||
apply: (target, self, args) => { | ||
delete Marionette["PageChangeToken"]; | ||
return target.apply(self, args); | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
window.$$marionette = Marionette; |