diff --git a/pywb/rewrite/rewrite_content.py b/pywb/rewrite/rewrite_content.py index c852633b..1e3b40e0 100644 --- a/pywb/rewrite/rewrite_content.py +++ b/pywb/rewrite/rewrite_content.py @@ -118,9 +118,22 @@ class RewriteContent: if head_insert_func: head_insert_str = head_insert_func(rule, cdx) + head_insert_str = head_insert_str.encode('utf-8') if wb_url.is_banner_only: gen = self._head_insert_only_gen(head_insert_str, stream) + + content_len = headers.get_header('Content-Length') + try: + content_len = int(content_len) + except Exception: + content_len = None + + if content_len and content_len >= 0: + content_len = str(content_len + len(head_insert_str)) + status_headers.replace_header('Content-Length', + content_len) + return (status_headers, gen, False) rewriter = rewriter_class(urlrewriter, @@ -162,7 +175,8 @@ class RewriteContent: matcher = self.HEAD_REGEX.search(buff) if matcher: - yield buff[:matcher.end()] + insert_str + yield buff[:matcher.end()] + yield insert_str yield buff[matcher.end():] else: yield insert_str diff --git a/pywb/static/wb.js b/pywb/static/wb.js index 6d261748..df085854 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -119,14 +119,36 @@ function remove_event(name, func, object) { } } -if ((window.self == window.top) && (window.self.top == window.top) && wbinfo) { - if (wbinfo.canon_url && (window.location.href != wbinfo.canon_url)) { +function notify_top() { + if (window.parent != window.top) { + return; + } + + if (!window.WB_wombat_location) { + return; + } + + if (typeof(window.WB_wombat_location.href) != "string") { + return; + } + + window.parent.update_wb_url(window.WB_wombat_location.href, + wbinfo.timestamp, + wbinfo.is_live); + + remove_event("readystatechange", notify_top, document); +} + +if ((window.self == window.top) && wbinfo) { + if (wbinfo.canon_url && (window.location.href != wbinfo.canon_url) && wbinfo.mod != "bn_") { // Auto-redirect to top frame window.location.replace(wbinfo.canon_url); } else { // Init Banner (no frame or top frame) add_event("readystatechange", init_banner, document); } +} else if (window.self != window.parent && window.parent.update_wb_url) { + add_event("readystatechange", notify_top, document); } diff --git a/pywb/static/wb_frame.js b/pywb/static/wb_frame.js index 48484e06..af1a66f2 100644 --- a/pywb/static/wb_frame.js +++ b/pywb/static/wb_frame.js @@ -1,7 +1,7 @@ -var update_wb_url = push_state; - var LIVE_COOKIE_REGEX = /pywb.timestamp=([\d]{1,14})/; +var curr_state = {}; + function make_outer_url(url, ts) { @@ -41,13 +41,13 @@ function push_state(url, timestamp, capture_str, is_live) { window.history.replaceState(state, "", state.outer_url); - update_status(state.capture_str, is_live); + set_state(state); } function pop_state(state) { - update_status(state.capture_str, state.is_live); + set_state(state); - window.frames[0].src = state.outer_url; + window.frames[0].src = state.inner_url; } function extract_ts(url) @@ -75,27 +75,29 @@ function extract_replay_url(url) { return url.substring(inx + 1); } -function update_status(str, is_live) { +function set_state(state) { var capture_info = document.getElementById("_wb_capture_info"); if (capture_info) { - capture_info.innerHTML = str; + capture_info.innerHTML = state.capture_str; } var label = document.getElementById("_wb_label"); if (label) { - if (is_live) { + if (state.is_live) { label.innerHTML = _wb_js.labels.LIVE_MSG; } else { label.innerHTML = _wb_js.labels.REPLAY_MSG; } } + + curr_state = state; } window.onpopstate = function(event) { - var curr_state = event.state; + var state = event.state; - if (curr_state) { - pop_state(curr_state); + if (state) { + pop_state(state); } } @@ -132,7 +134,16 @@ function iframe_loaded(event) { ts = extract_ts(iframe.location.href); } } + + update_wb_url(url, ts, is_live); +} + +function update_wb_url(url, ts, is_live) { + if (curr_state.url == url && curr_state.timestamp == ts) { + return; + } + capture_str = _wb_js.ts_to_date(ts, true); - update_wb_url(url, ts, capture_str, is_live); + push_state(url, ts, capture_str, is_live); } diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index e14c9d7d..962a32cd 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -699,7 +699,7 @@ WB_wombat_init = (function() { wb_replay_prefix = replay_prefix; if (wb_replay_prefix) { - wb_replay_date_prefix = replay_prefix + capture_date + "em_/"; + wb_replay_date_prefix = replay_prefix + capture_date + "mp_/"; if (capture_date.length > 0) { wb_capture_date_part = "/" + capture_date + "/"; diff --git a/pywb/ui/head_insert.html b/pywb/ui/head_insert.html index 115734a1..c863ed70 100644 --- a/pywb/ui/head_insert.html +++ b/pywb/ui/head_insert.html @@ -14,7 +14,7 @@ wbinfo = {} wbinfo.timestamp = "{{ cdx.timestamp }}"; wbinfo.prefix = "{{ wbrequest.wb_prefix }}"; - wbinfo.is_frame_mp = {{"true" if wbrequest.wb_url.mod == 'mp_' else "false"}}; + wbinfo.mod = "{{ wbrequest.wb_url.mod }}"; wbinfo.canon_url = "{{ canon_url }}"; wbinfo.is_live = {{ "true" if cdx.is_live else "false" }}; wbinfo.is_proxy_mode = {{ "true" if wbrequest.options.is_proxy else "false" }};