kopia lustrzana https://github.com/browsh-org/browsh
HTTP server: add experimental DOM-dump mode
Simply dumps the contents of the DOMpull/286/head
rodzic
81f41b7b4c
commit
d6b5951059
|
@ -225,6 +225,7 @@ func isProductionHTTP(r *http.Request) bool {
|
|||
|
||||
// 'PLAIN' mode returns raw text without any HTML whatsoever.
|
||||
// 'HTML' mode returns some basic HTML tags for things like anchor links.
|
||||
// 'DOM' mode returns a simple dump of the DOM.
|
||||
func getRawTextMode(r *http.Request) string {
|
||||
var mode = "HTML"
|
||||
if strings.Contains(r.Host, "text.") {
|
||||
|
@ -233,6 +234,9 @@ func getRawTextMode(r *http.Request) string {
|
|||
if r.Header.Get("X-Browsh-Raw-Mode") == "PLAIN" {
|
||||
mode = "PLAIN"
|
||||
}
|
||||
if r.Header.Get("X-Browsh-Raw-Mode") == "DOM" {
|
||||
mode = "DOM"
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package browsh
|
||||
|
||||
var browshVersion = "1.6.1"
|
||||
var browshVersion = "1.6.2"
|
||||
|
|
|
@ -29,6 +29,12 @@ var _ = Describe("HTTP Server", func() {
|
|||
"<a href=\"/http://localhost:4444/smorgasbord/another.html\">Another page</a>"))
|
||||
})
|
||||
|
||||
It("should return the DOM", func() {
|
||||
response := getPath("/smorgasbord", "dom")
|
||||
Expect(response).To(ContainSubstring(
|
||||
"<div class=\"big_middle\">"))
|
||||
})
|
||||
|
||||
It("should return a background image", func() {
|
||||
response := getPath("/smorgasbord", "html")
|
||||
Expect(response).To(ContainSubstring("background-image: url(data:image/jpeg"))
|
||||
|
|
|
@ -51,6 +51,9 @@ func getPath(path string, mode string) string {
|
|||
if mode == "plain" {
|
||||
request.Header.Add("X-Browsh-Raw-Mode", "PLAIN")
|
||||
}
|
||||
if mode == "dom" {
|
||||
request.Header.Add("X-Browsh-Raw-Mode", "DOM")
|
||||
}
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("%s", err))
|
||||
|
|
|
@ -50,7 +50,7 @@ export default MixinBase =>
|
|||
|
||||
_launch() {
|
||||
const mode = this.config.http_server_mode_type;
|
||||
if (mode === "raw_text_plain" || mode === "raw_text_html") {
|
||||
if (mode.includes("raw_text_")) {
|
||||
this._is_raw_text_mode = true;
|
||||
this._is_interactive_mode = false;
|
||||
this._raw_mode_type = mode;
|
||||
|
|
|
@ -289,8 +289,14 @@ export default MixinBase =>
|
|||
}
|
||||
|
||||
_sendRawText() {
|
||||
let body;
|
||||
if (this._raw_mode_type == "raw_text_dom") {
|
||||
body = document.getElementsByTagName("body")[0].innerHTML;
|
||||
} else {
|
||||
body = this._serialiseRawText();
|
||||
}
|
||||
let payload = {
|
||||
body: this._serialiseRawText(),
|
||||
body: body,
|
||||
page_load_duration: this.config.page_load_duration,
|
||||
parsing_duration: this._parsing_duration
|
||||
};
|
||||
|
|
|
@ -30,7 +30,13 @@ export default class extends utils.mixins(CommonMixin, SerialiseMixin) {
|
|||
sendRawText(type) {
|
||||
this._raw_mode_type = type;
|
||||
this._parse_start_time = performance.now();
|
||||
this.buildFormattedText(this._sendRawText.bind(this));
|
||||
if (type == "raw_text_dom") {
|
||||
setTimeout(() => {
|
||||
this._sendRawText();
|
||||
}, this.config["http-server"].render_delay);
|
||||
} else {
|
||||
this.buildFormattedText(this._sendRawText.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
buildFormattedText(callback) {
|
||||
|
|
Ładowanie…
Reference in New Issue