mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
client rewrite: improvements for proxy mode
- disable most overrides when in proxy mode - if using rewrite_url(), keep current scheme, instead of defaulting to http - use 'window._wb_js' to check init
This commit is contained in:
parent
bdf4f9bc71
commit
718cd43ae2
@ -18,7 +18,7 @@ This file is part of pywb, https://github.com/ikreymer/pywb
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
// Wombat JS-Rewriting Library v2.16
|
// Wombat JS-Rewriting Library v2.17
|
||||||
//============================================
|
//============================================
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
// custom options
|
// custom options
|
||||||
var wb_opts;
|
var wb_opts;
|
||||||
|
|
||||||
|
var wb_is_proxy = false;
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function is_host_url(str) {
|
function is_host_url(str) {
|
||||||
// Good guess that's its a hostname
|
// Good guess that's its a hostname
|
||||||
@ -160,10 +162,12 @@ var wombat_internal = function($wbwindow) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// proxy mode: If no wb_replay_prefix, only rewrite https:// -> http://
|
// proxy mode: If no wb_replay_prefix, only rewrite scheme
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
if (starts_with(url, HTTPS_PREFIX)) {
|
if (wb_orig_scheme == HTTP_PREFIX && starts_with(url, HTTPS_PREFIX)) {
|
||||||
return HTTP_PREFIX + url.substr(HTTPS_PREFIX.length);
|
return HTTP_PREFIX + url.substr(HTTPS_PREFIX.length);
|
||||||
|
} else if (wb_orig_scheme == HTTPS_PREFIX && starts_with(url, HTTP_PREFIX)) {
|
||||||
|
return HTTPS_PREFIX + url.substr(HTTP_PREFIX.length);
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@ -317,7 +321,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
var orig_href = href;
|
var orig_href = href;
|
||||||
|
|
||||||
// proxy mode: no extraction needed
|
// proxy mode: no extraction needed
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2282,24 +2286,31 @@ var wombat_internal = function($wbwindow) {
|
|||||||
wb_info = wbinfo;
|
wb_info = wbinfo;
|
||||||
wb_opts = wbinfo.wombat_opts;
|
wb_opts = wbinfo.wombat_opts;
|
||||||
wb_replay_prefix = wbinfo.prefix;
|
wb_replay_prefix = wbinfo.prefix;
|
||||||
|
wb_is_proxy = (!wb_replay_prefix);
|
||||||
|
|
||||||
wb_info.top_host = wb_info.top_host || "*";
|
wb_info.top_host = wb_info.top_host || "*";
|
||||||
|
|
||||||
init_top_frame($wbwindow);
|
init_top_frame($wbwindow);
|
||||||
init_wombat_top($wbwindow);
|
|
||||||
|
|
||||||
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
init_wombat_loc($wbwindow);
|
||||||
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
|
||||||
} else {
|
|
||||||
wb_rel_prefix = wb_replay_prefix;
|
|
||||||
}
|
|
||||||
wb_rel_prefix_check = wb_rel_prefix;
|
|
||||||
|
|
||||||
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
||||||
|
|
||||||
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
||||||
|
|
||||||
|
// archival mode: init url-rewriting intercepts
|
||||||
|
if (!wb_is_proxy) {
|
||||||
|
init_wombat_top($wbwindow);
|
||||||
|
|
||||||
|
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
||||||
|
|
||||||
|
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
||||||
|
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
||||||
|
} else {
|
||||||
|
wb_rel_prefix = wb_replay_prefix;
|
||||||
|
}
|
||||||
|
wb_rel_prefix_check = wb_rel_prefix;
|
||||||
|
|
||||||
if (wb_replay_prefix) {
|
|
||||||
wb_abs_prefix = wb_replay_prefix;
|
wb_abs_prefix = wb_replay_prefix;
|
||||||
//wb_replay_date_prefix = wb_replay_prefix + ts_mod;
|
//wb_replay_date_prefix = wb_replay_prefix + ts_mod;
|
||||||
//wb_coll_prefix += ts_mod;
|
//wb_coll_prefix += ts_mod;
|
||||||
@ -2310,93 +2321,95 @@ var wombat_internal = function($wbwindow) {
|
|||||||
wb_capture_date_part = "";
|
wb_capture_date_part = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
|
||||||
|
|
||||||
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
||||||
|
|
||||||
init_bad_prefixes(wb_replay_prefix);
|
init_bad_prefixes(wb_replay_prefix);
|
||||||
|
|
||||||
|
//if ($wbwindow.opener) {
|
||||||
|
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Domain
|
||||||
|
//$wbwindow.document.WB_wombat_domain = wbinfo.wombat_host;
|
||||||
|
//$wbwindow.document.WB_wombat_referrer = extract_orig($wbwindow.document.referrer);
|
||||||
|
|
||||||
|
init_doc_overrides($wbwindow, wb_opts);
|
||||||
|
|
||||||
|
// History
|
||||||
|
override_history_func("pushState");
|
||||||
|
override_history_func("replaceState");
|
||||||
|
|
||||||
|
override_history_nav("go");
|
||||||
|
override_history_nav("back");
|
||||||
|
override_history_nav("forward");
|
||||||
|
|
||||||
|
// postMessage
|
||||||
|
// OPT skip
|
||||||
|
if (!wb_opts.skip_postmessage) {
|
||||||
|
init_postmessage_override($wbwindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
init_hash_change();
|
||||||
|
|
||||||
|
// write
|
||||||
|
init_write_override();
|
||||||
|
|
||||||
|
// Ajax
|
||||||
|
init_ajax_rewrite();
|
||||||
|
|
||||||
|
if (!wb_opts.skip_disable_worker) {
|
||||||
|
//init_worker_override();
|
||||||
|
}
|
||||||
|
|
||||||
|
// innerHTML can be overriden on prototype!
|
||||||
|
override_html_assign($wbwindow.HTMLElement, "innerHTML");
|
||||||
|
override_html_assign($wbwindow.HTMLIFrameElement, "srcdoc");
|
||||||
|
override_html_assign($wbwindow.HTMLStyleElement, "textContent");
|
||||||
|
|
||||||
|
|
||||||
|
// init insertAdjacentHTML() override
|
||||||
|
init_insertAdjacentHTML_override();
|
||||||
|
|
||||||
|
// iframe.contentWindow and iframe.contentDocument overrides to
|
||||||
|
// ensure wombat is inited on the iframe $wbwindow!
|
||||||
|
override_iframe_content_access("contentWindow");
|
||||||
|
override_iframe_content_access("contentDocument");
|
||||||
|
|
||||||
|
// base override
|
||||||
|
init_base_override();
|
||||||
|
|
||||||
|
// setAttribute
|
||||||
|
if (!wb_opts.skip_setAttribute) {
|
||||||
|
init_setAttribute_override();
|
||||||
|
init_getAttribute_override();
|
||||||
|
}
|
||||||
|
|
||||||
|
// createElement attr override
|
||||||
|
if (!wb_opts.skip_createElement) {
|
||||||
|
init_createElement_override();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure namespace urls are NOT rewritten
|
||||||
|
init_createElementNS_fix();
|
||||||
|
|
||||||
|
// Image
|
||||||
|
//init_image_override();
|
||||||
|
|
||||||
|
// DOM
|
||||||
|
// OPT skip
|
||||||
|
if (!wb_opts.skip_dom) {
|
||||||
|
init_dom_override();
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerProtocolHandler override
|
||||||
|
init_registerPH_override();
|
||||||
|
|
||||||
|
//sendBeacon override
|
||||||
|
init_beacon_override();
|
||||||
}
|
}
|
||||||
|
|
||||||
init_wombat_loc($wbwindow);
|
// other overrides
|
||||||
|
// proxy mode: only using these overrides
|
||||||
//if ($wbwindow.opener) {
|
|
||||||
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Domain
|
|
||||||
//$wbwindow.document.WB_wombat_domain = wbinfo.wombat_host;
|
|
||||||
//$wbwindow.document.WB_wombat_referrer = extract_orig($wbwindow.document.referrer);
|
|
||||||
|
|
||||||
init_doc_overrides($wbwindow, wb_opts);
|
|
||||||
|
|
||||||
// History
|
|
||||||
override_history_func("pushState");
|
|
||||||
override_history_func("replaceState");
|
|
||||||
|
|
||||||
override_history_nav("go");
|
|
||||||
override_history_nav("back");
|
|
||||||
override_history_nav("forward");
|
|
||||||
|
|
||||||
// open
|
|
||||||
init_open_override();
|
|
||||||
|
|
||||||
// postMessage
|
|
||||||
// OPT skip
|
|
||||||
if (!wb_opts.skip_postmessage) {
|
|
||||||
init_postmessage_override($wbwindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
init_hash_change();
|
|
||||||
|
|
||||||
// write
|
|
||||||
init_write_override();
|
|
||||||
|
|
||||||
// Ajax
|
|
||||||
init_ajax_rewrite();
|
|
||||||
|
|
||||||
if (!wb_opts.skip_disable_worker) {
|
|
||||||
//init_worker_override();
|
|
||||||
}
|
|
||||||
|
|
||||||
// innerHTML can be overriden on prototype!
|
|
||||||
override_html_assign($wbwindow.HTMLElement, "innerHTML");
|
|
||||||
override_html_assign($wbwindow.HTMLIFrameElement, "srcdoc");
|
|
||||||
override_html_assign($wbwindow.HTMLStyleElement, "textContent");
|
|
||||||
|
|
||||||
|
|
||||||
// init insertAdjacentHTML() override
|
|
||||||
init_insertAdjacentHTML_override();
|
|
||||||
|
|
||||||
// iframe.contentWindow and iframe.contentDocument overrides to
|
|
||||||
// ensure wombat is inited on the iframe $wbwindow!
|
|
||||||
override_iframe_content_access("contentWindow");
|
|
||||||
override_iframe_content_access("contentDocument");
|
|
||||||
|
|
||||||
// base override
|
|
||||||
init_base_override();
|
|
||||||
|
|
||||||
// setAttribute
|
|
||||||
if (!wb_opts.skip_setAttribute) {
|
|
||||||
init_setAttribute_override();
|
|
||||||
init_getAttribute_override();
|
|
||||||
}
|
|
||||||
|
|
||||||
// createElement attr override
|
|
||||||
if (!wb_opts.skip_createElement) {
|
|
||||||
init_createElement_override();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure namespace urls are NOT rewritten
|
|
||||||
init_createElementNS_fix();
|
|
||||||
|
|
||||||
// Image
|
|
||||||
//init_image_override();
|
|
||||||
|
|
||||||
// DOM
|
|
||||||
// OPT skip
|
|
||||||
if (!wb_opts.skip_dom) {
|
|
||||||
init_dom_override();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Random
|
// Random
|
||||||
init_seeded_random(wbinfo.wombat_sec);
|
init_seeded_random(wbinfo.wombat_sec);
|
||||||
@ -2407,11 +2420,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
// Date
|
// Date
|
||||||
init_date_override(wbinfo.wombat_sec);
|
init_date_override(wbinfo.wombat_sec);
|
||||||
|
|
||||||
// registerProtocolHandler override
|
// open
|
||||||
init_registerPH_override();
|
init_open_override();
|
||||||
|
|
||||||
//sendBeacon override
|
|
||||||
init_beacon_override();
|
|
||||||
|
|
||||||
// expose functions
|
// expose functions
|
||||||
this.extract_orig = extract_orig;
|
this.extract_orig = extract_orig;
|
||||||
@ -2422,7 +2432,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
function init_top_frame($wbwindow) {
|
function init_top_frame($wbwindow) {
|
||||||
// proxy mode
|
// proxy mode
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
$wbwindow.__WB_replay_top = $wbwindow.top;
|
$wbwindow.__WB_replay_top = $wbwindow.top;
|
||||||
$wbwindow.__WB_top_frame = undefined;
|
$wbwindow.__WB_top_frame = undefined;
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
{% include banner_html ignore missing %}
|
{% include banner_html ignore missing %}
|
||||||
|
|
||||||
<!-- load banner -->
|
<!-- load banner -->
|
||||||
<script> if (_wb_js) { _wb_js.load(); }</script>
|
<script> if (window._wb_js) { _wb_js.load(); }</script>
|
||||||
|
|
||||||
{#
|
{#
|
||||||
<!-- workaround for chrome iframe scrolling issue -->
|
<!-- workaround for chrome iframe scrolling issue -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user