mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
client-side rewrite fixes:
- override Function.apply() to de-proxy thisArg and all params before calling native functions (may make per-function overrides unnecessary) - ensure init_top_frame_notify() is called on $wbwindow object not window
This commit is contained in:
parent
728d9b3ca1
commit
448fb2cf1e
@ -2393,6 +2393,36 @@ var _WBWombat = function($wbwindow, wbinfo) {
|
|||||||
prototype[method] = deproxy;
|
prototype[method] = deproxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================
|
||||||
|
function override_apply_func($wbwindow) {
|
||||||
|
if ($wbwindow.Function.prototype.__WB_orig_apply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var orig_func_to_string = Function.prototype.toString;
|
||||||
|
|
||||||
|
var orig_apply = $wbwindow.Function.prototype.apply;
|
||||||
|
|
||||||
|
$wbwindow.Function.prototype.__WB_orig_apply = orig_apply;
|
||||||
|
|
||||||
|
function deproxy(obj, args) {
|
||||||
|
if (orig_func_to_string.call(this).indexOf("[native code]") >= 0) {
|
||||||
|
if (args) {
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
args[i] = proxy_to_obj(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
obj = proxy_to_obj(obj);
|
||||||
|
}
|
||||||
|
return this.__WB_orig_apply(obj, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
$wbwindow.Function.prototype.apply = deproxy;
|
||||||
|
orig_func_to_string.apply = orig_apply;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function init_open_override()
|
function init_open_override()
|
||||||
{
|
{
|
||||||
@ -3153,6 +3183,8 @@ var _WBWombat = function($wbwindow, wbinfo) {
|
|||||||
override_func_this_proxy_to_obj($wbwindow.EventTarget, "addEventListener");
|
override_func_this_proxy_to_obj($wbwindow.EventTarget, "addEventListener");
|
||||||
override_func_this_proxy_to_obj($wbwindow.EventTarget, "removeEventListener");
|
override_func_this_proxy_to_obj($wbwindow.EventTarget, "removeEventListener");
|
||||||
|
|
||||||
|
override_apply_func($wbwindow);
|
||||||
|
|
||||||
override_frames_access($wbwindow);
|
override_frames_access($wbwindow);
|
||||||
|
|
||||||
// setAttribute
|
// setAttribute
|
||||||
@ -3231,55 +3263,55 @@ var _WBWombat = function($wbwindow, wbinfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wbinfo.is_framed && wbinfo.mod != "bn_") {
|
if (wbinfo.is_framed && wbinfo.mod != "bn_") {
|
||||||
init_frame_notify();
|
init_top_frame_notify(wbinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_frame_notify() {
|
function init_top_frame_notify(wbinfo) {
|
||||||
function notify_top(event) {
|
function notify_top(event) {
|
||||||
if (!window.__WB_top_frame) {
|
if (!$wbwindow.__WB_top_frame) {
|
||||||
var hash = window.location.hash;
|
var hash = $wbwindow.location.hash;
|
||||||
|
|
||||||
//var loc = window.location.href.replace(window.location.hash, "");
|
//var loc = window.location.href.replace(window.location.hash, "");
|
||||||
//loc = decodeURI(loc);
|
//loc = decodeURI(loc);
|
||||||
|
|
||||||
//if (wbinfo.top_url && (loc != decodeURI(wbinfo.top_url))) {
|
//if (wbinfo.top_url && (loc != decodeURI(wbinfo.top_url))) {
|
||||||
// Auto-redirect to top frame
|
// Auto-redirect to top frame
|
||||||
window.location.replace(wbinfo.top_url + hash);
|
$wbwindow.location.replace(wbinfo.top_url + hash);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window.WB_wombat_location) {
|
if (!$wbwindow.WB_wombat_location) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof(window.WB_wombat_location.href) != "string") {
|
if (typeof($wbwindow.WB_wombat_location.href) != "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
"url": window.WB_wombat_location.href,
|
"url": $wbwindow.WB_wombat_location.href,
|
||||||
"ts": wbinfo.timestamp,
|
"ts": wbinfo.timestamp,
|
||||||
"request_ts": wbinfo.request_ts,
|
"request_ts": wbinfo.request_ts,
|
||||||
"is_live": wbinfo.is_live,
|
"is_live": wbinfo.is_live,
|
||||||
"title": document ? document.title : "",
|
"title": $wbwindow.document ? $wbwindow.document.title : "",
|
||||||
"readyState": document.readyState,
|
"readyState": $wbwindow.document.readyState,
|
||||||
"wb_type": "load"
|
"wb_type": "load"
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__WB_top_frame.postMessage(message, wbinfo.top_host);
|
$wbwindow.__WB_top_frame.postMessage(message, wbinfo.top_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState == "complete") {
|
if ($wbwindow.document.readyState == "complete") {
|
||||||
notify_top();
|
notify_top();
|
||||||
} else if (window.addEventListener) {
|
} else if ($wbwindow.addEventListener) {
|
||||||
document.addEventListener("readystatechange", notify_top);
|
$wbwindow.document.addEventListener("readystatechange", notify_top);
|
||||||
} else if (window.attachEvent) {
|
} else if ($wbwindow.attachEvent) {
|
||||||
document.attachEvent("onreadystatechange", notify_top);
|
$wbwindow.document.attachEvent("onreadystatechange", notify_top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user