mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
Merge branch 'frame-postMessage' into develop
This commit is contained in:
commit
f858be4d7d
@ -123,12 +123,23 @@ function notify_top() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.__WB_top_frame.update_wb_url) {
|
//if (window.__WB_top_frame.update_wb_url) {
|
||||||
window.__WB_top_frame.update_wb_url(window.WB_wombat_location.href,
|
// window.__WB_top_frame.update_wb_url(window.WB_wombat_location.href,
|
||||||
wbinfo.timestamp,
|
// wbinfo.timestamp,
|
||||||
wbinfo.request_ts,
|
// wbinfo.request_ts,
|
||||||
wbinfo.is_live);
|
// wbinfo.is_live);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
var message = {
|
||||||
|
"url": window.WB_wombat_location.href,
|
||||||
|
"ts": wbinfo.timestamp,
|
||||||
|
"request_ts": wbinfo.request_ts,
|
||||||
|
"is_live": wbinfo.is_live,
|
||||||
|
"title": "",
|
||||||
|
"wb_type": "load",
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__WB_top_frame.postMessage(message, "*");
|
||||||
|
|
||||||
remove_event("readystatechange", notify_top, document);
|
remove_event("readystatechange", notify_top, document);
|
||||||
}
|
}
|
||||||
|
@ -38,27 +38,21 @@ function make_url(url, ts, mod)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function push_state(url, timestamp, request_ts, capture_str, is_live) {
|
function push_state(state) {
|
||||||
var frame = document.getElementById(IFRAME_ID).contentWindow;
|
var frame = document.getElementById(IFRAME_ID).contentWindow;
|
||||||
if (frame.WB_wombat_location) {
|
if (frame.WB_wombat_location) {
|
||||||
var curr_href = frame.WB_wombat_location.href;
|
var curr_href = frame.WB_wombat_location.href;
|
||||||
|
|
||||||
// If not current url, don't update
|
// If not current url, don't update
|
||||||
if (url != curr_href) {
|
if (state.url != curr_href) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = {}
|
state.outer_url = make_url(state.url, state.request_ts, wbinfo.frame_mod);
|
||||||
state.timestamp = timestamp;
|
state.inner_url = make_url(state.url, state.request_ts, wbinfo.replay_mod);
|
||||||
state.request_ts = request_ts;
|
|
||||||
state.outer_url = make_url(url, state.request_ts, wbinfo.frame_mod);
|
|
||||||
state.inner_url = make_url(url, state.request_ts, wbinfo.replay_mod);
|
|
||||||
state.url = url;
|
|
||||||
state.capture_str = capture_str;
|
|
||||||
state.is_live = is_live;
|
|
||||||
|
|
||||||
var canon_url = make_url(url, state.request_ts, "");
|
var canon_url = make_url(state.url, state.request_ts, "");
|
||||||
if (window.location.href != canon_url) {
|
if (window.location.href != canon_url) {
|
||||||
window.history.replaceState(state, "", canon_url);
|
window.history.replaceState(state, "", canon_url);
|
||||||
}
|
}
|
||||||
@ -157,7 +151,13 @@ function iframe_loaded(event) {
|
|||||||
request_ts = ts;
|
request_ts = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_wb_url(url, ts, request_ts, is_live);
|
var state = {}
|
||||||
|
state["url"] = url;
|
||||||
|
state["ts"] = ts;
|
||||||
|
state["request_ts"] = request_ts;
|
||||||
|
state["is_live"] = is_live
|
||||||
|
|
||||||
|
update_wb_url(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,12 +165,18 @@ function init_pm() {
|
|||||||
var frame = document.getElementById(IFRAME_ID).contentWindow;
|
var frame = document.getElementById(IFRAME_ID).contentWindow;
|
||||||
|
|
||||||
window.addEventListener("message", function(event) {
|
window.addEventListener("message", function(event) {
|
||||||
// Pass to replay frame
|
|
||||||
if (event.source == window.parent) {
|
if (event.source == window.parent) {
|
||||||
|
// Pass to replay frame
|
||||||
frame.postMessage(event.data, "*");
|
frame.postMessage(event.data, "*");
|
||||||
} else if (event.source == frame) {
|
} else if (event.source == frame) {
|
||||||
// Pass to parent
|
|
||||||
window.parent.postMessage(event.data, "*");
|
// Check if iframe url change message
|
||||||
|
if (typeof(event.data) == "object" && event.data["wb_type"]) {
|
||||||
|
update_wb_url(event.data);
|
||||||
|
} else {
|
||||||
|
// Pass to parent
|
||||||
|
window.parent.postMessage(event.data, "*");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,14 +187,14 @@ function init_pm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function update_wb_url(url, ts, request_ts, is_live) {
|
function update_wb_url(state) {
|
||||||
if (curr_state.url == url && curr_state.timestamp == ts) {
|
if (curr_state.url == state.url && curr_state.ts == state.ts) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
capture_str = _wb_js.ts_to_date(ts, true);
|
state['capture_str'] = _wb_js.ts_to_date(state.ts, true);
|
||||||
|
|
||||||
push_state(url, ts, request_ts, capture_str, is_live);
|
push_state(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load Banner
|
// Load Banner
|
||||||
@ -237,3 +243,4 @@ function init_hash_connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", init_hash_connect);
|
document.addEventListener("DOMContentLoaded", init_hash_connect);
|
||||||
|
|
||||||
|
@ -718,11 +718,23 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
orig_func.call(this, state_obj, title, url);
|
orig_func.call(this, state_obj, title, url);
|
||||||
|
|
||||||
if ($wbwindow.__WB_top_frame && $wbwindow != $wbwindow.__WB_top_frame && $wbwindow.__WB_top_frame.update_wb_url) {
|
//if ($wbwindow.__WB_top_frame && $wbwindow != $wbwindow.__WB_top_frame && $wbwindow.__WB_top_frame.update_wb_url) {
|
||||||
$wbwindow.__WB_top_frame.update_wb_url($wbwindow.WB_wombat_location.href,
|
// $wbwindow.__WB_top_frame.update_wb_url($wbwindow.WB_wombat_location.href,
|
||||||
wb_info.timestamp,
|
// wb_info.timestamp,
|
||||||
wb_info.request_ts,
|
// wb_info.request_ts,
|
||||||
wb_info.is_live);
|
// wb_info.is_live);
|
||||||
|
//}
|
||||||
|
if ($wbwindow.__WB_top_frame && $wbwindow != $wbwindow.__WB_top_frame) {
|
||||||
|
var message = {
|
||||||
|
"url": url,
|
||||||
|
"ts": wb_info.timestamp,
|
||||||
|
"request_ts": wb_info.request_ts,
|
||||||
|
"is_live": wb_info.is_live,
|
||||||
|
"title": title,
|
||||||
|
"wb_type": func_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
$wbwindow.__WB_top_frame.postMessage(message, "*");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user